Author Topic: bash question for quadz, or any programmers  (Read 1935 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:

 

Yotematoi

May 17, 2025, 08:33:15 AM
Yo desde el año 2007 me enfermé de Q2, es incurable  
Morir y revivir es costumbre, lástima q el QT estaba bueno
 

ImperiusDamian

May 12, 2025, 01:45:35 AM
Quake II is not 27 years old. I refuse to accept THAT much time has gone by.
 

|iR|Focalor

May 11, 2025, 02:33:39 PM
 

-Unh0ly-

May 03, 2025, 08:02:46 AM
198.179.6.200:30634
 

Yotematoi

May 02, 2025, 10:27:47 AM
Note for Player-4109 "Remember, the Guinness Book of Records does not include cowards who shot at someone by treachery." :D
 

|iR|Focalor

April 02, 2025, 02:47:07 AM
 

Yotematoi

February 14, 2025, 12:41:48 PM
 :-*
 

|iR|Focalor

February 13, 2025, 07:31:24 AM
I was on DM this morning for the first time in a pretty long time. Seemed fine to me.

0rbisson

February 13, 2025, 04:54:21 AM
DM server is fucked. 2 point blank rockets from spawn and lava damage and player survived? WTF?" Also someone has fucked with the spawn points, every single time no matter how big the map you spawn right in front of the person who killed you last

Show 50 latest
Welcome, Guest. Please login or register.
May 18, 2025, 01:59:13 PM

Login with username, password and session length