Author Topic: bash question for quadz, or any programmers  (Read 1830 times)

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
bash question for quadz, or any programmers
« on: May 07, 2007, 10:58:47 AM »
Hi Quadz, seeing as you are a super nice guy I figured you might be able to help, this might be something you know of the top of your head.  My goal is to create automated backups of router/switch configuration files, and system images.  Changes are frequently made, and the last thing I want is to fix some switch without a config, when the switch does load-balancing, has a 100 vlans, and all that other fun stuff.

SNMP, and Expect, are the only options to do this (you cannot use Kron on Cisco routers for interactive commands).  So you can issue an SNMP get request, or automate what you would type with expect.

SNMP is probably the cleanest way to do this, since it's quicker, and doesn't actually log in to the router.  But I'm only doing this for five or so routers, and I don't know the OIDs to get the config, nor do I feel like using snmpwalk.  Either way the tools already created aren't to much help, as each router has unique OIDs, and they use expect, and snmp as is.  Plus .. this is supposed to be fun : )

What I have working (below), is an expect script connecting to a router, it then issues the commands to download the configs, and this script will be scheduled to run.  This works, my problem is - how do I close the damn window!@?

Since this script will be run often, and there will be similiar scripts, I can't have a million windows keep opening.  If it was a bash script, I believe I can just end the script with exit 0.  I tried programs to start cygwin in the system tray, but they don't seem to work, and that's not really what I wanna do. 

If I was to type expect within bash, I would get an expect prompt.  If I were to type exit I would go to bash, expect is a shell like bash, but with additional commands, and some bash commands not available.  I tried sending the encoded equivalent of control+D, and that did not work, it was fun, now I am really frustrated : /


#!/usr/bin/expect -f
#creating temporary file from bash date command
#the date will be used to give the router configuration files a unique name

exec  date +%y%d%h >/tmp/datesync.tmp
exec cat /tmp/datesync.tmp
set newtime [exec cat /tmp/datesync.tmp]


#grab config from router

spawn telnet 69.x.x.10
expect "Password:"
send "*******\r"
expect "xp>"
send "enable\r"
expect "Password:"
send "*********\r"
expect "xp#"
send "copy startup to tftp-server\r"
expect "tftp-server"
send "66.x.x.81\r"
expect "filename"
send "$newtime cabletron \r"
expect "xp#"
send "exit\r"
expect "xp>"
send "exit\r"


#delete temporary file
exec rm /tmp/datesync.tmp

exit 0


  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: bash question for quadz, or any programmers
« Reply #1 on: May 07, 2007, 12:46:25 PM »
well I found a workaround, but it's not ideal (the windows don't instantly close), I schedule a job right after the scripts are run, which is just a .bat file that uses tskill bash.. but I want to close the windows at the end when they are open.  really i'd like to not have them visible when the scripts or run, but I did a man bash, and checked google.com and didn't know what was up : (.  there has to be a better way to do this.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: bash question for quadz, or any programmers
« Reply #2 on: May 08, 2007, 08:22:00 AM »
still having problems with this.
my problem is after each expect script runs I want to close the cygwin window.

I think if I run a bash script, and call the expect script from within bash, it should work.
« Last Edit: May 08, 2007, 09:04:14 AM by reaper »
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: bash question for quadz, or any programmers
« Reply #3 on: May 09, 2007, 01:52:50 PM »
thanks you quadz@!!!!!!!

i was editing the shell script in notepad, and notepad was sending /r CR, not /n LF. is working now!
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

 

El Box de Shoutamente

Last 10 Shouts:

 

Costigan_Q2

November 11, 2024, 06:41:06 AM
"Stay cozy folks.

Everything is gonna be fine."

There'll be no excuses for having TDS after January 20th, there'll be no excuses AT ALL!!!
 

|iR|Focalor

November 06, 2024, 03:28:50 AM
 

RailWolf

November 05, 2024, 03:13:44 PM
Nice :)

Tom Servo

November 04, 2024, 05:05:24 PM
The Joe Rogan Experience episode 223 that dropped a couple hours ago with Musk, they're talking about Quake lol.
 

Costigan_Q2

November 04, 2024, 03:37:55 PM
Stay cozy folks.

Everything is gonna be fine.
 

|iR|Focalor

October 31, 2024, 08:56:37 PM
 

Costigan_Q2

October 17, 2024, 06:31:53 PM
Not activated your account yet?

Activate it now! join in the fun!

Tom Servo

October 11, 2024, 03:35:36 PM
HAHAHAHAHAHA
 

|iR|Focalor

October 10, 2024, 12:19:41 PM
I don't worship the devil. Jesus is Lord, friend. He died for your sins. He will forgive you if you just ask.
 

rikwad

October 09, 2024, 07:57:21 PM
Sorry, I couldn't resist my inner asshole.

Show 50 latest
Welcome, Guest. Please login or register.
November 16, 2024, 03:43:19 AM

Login with username, password and session length