Re: bash basics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23 Oct 2002, H M Kunzmann wrote:

=>I have the following two scripts (below) that I've gotten a bit confused
=>with.
=>
=>What I want to do is dump a daily log of the router ip accounting into a
=>text file for that day.
=>
=>The bash script 'runlog' runs the expect scripts 'commands'.
=>
=>If I run '#expect commands' I get the output I want.
=>If I run 'runlog' the process runs through once and then stop
=>responding, and doesn't iterate.
=>
=>I ended up writing the runlog script because a cron job for 'expect
=>commands >> logfile' did not run, but did create the file.
=>
=>I'm a bit lost and a nudge in the right direction would be greatly
=>appreciated.
=>
=>
=>#!/bin/bash
=>
=>today=/logs/$(date +%Y-%m-%d)$1.log
=>
=>#echo Starting Router log...
=>expect -f /root/commands >> $today
=>
=>echo Completed router log for $today. Sleeping for 10 minutes.
=>sleep 10m
=>exec /root/runlog
=>
=>
=>#!/usr/bin/expect -f
=>spawn telnet xxx.xxx.xxx.xxx
=>
=>send "xxxxxx\r"
=>send "en\r"
=>send "xxxxxx\r"
=>wait -nowait
=>
=>send "term len 0\r"
=>send "sh ip accou\r"
=>wait -nowait
=>
=>send "clear ip acco\r"
=>wait -nowait
=>
=>send "exit\r"
=>interact
The expect script needs to begin with the proper shebang:

#! /usr/bin/expect --

It's not clear what you're doing. The shell script and the expect script 
must be in seperate files.

No need to surround the value of the today variable value in double 
quotes. (It doesn't hurt.) No need for the 10 minute sleep. The expect 
script has an interact statement at the end indicating that this does 
*not* want to be run from a cron job. It would just hang and never exit. 
The invocation of runlog using exec is ok, even though it doesn't buy you 
much.

-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? steveo@syslang.net



-- 
Psyche-list mailing list
Psyche-list@redhat.com
https://listman.redhat.com/mailman/listinfo/psyche-list

[Index of Archives]     [Fedora General Discussion]     [Red Hat General Discussion]     [Centos]     [Kernel]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat 9]     [Gimp]     [Yosemite News]

  Powered by Linux