ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have written a script that telnets 100 servers and gets a command output. I have written an "Expect" Script that does the telent functioning. Shell script calls the expect script to telnet each server
The script runs with No issues when executed manually.
But, when I run the script via Cron, the expect script is not getting called.
Is that the entire script in cron?
Where are $server, $Username, $Password getting set?
In any case, the default env in cron is minimal, so ALWAYS specify the complete (absolute) path to ALL cmds and files.
Something like
Thanks for the quick reply. The variables are in the Shell Script
I call them in the expect Script like this
#!/usr/bin/expect -f
set timeout -1
spawn $env(SHELL)
match_max 100000
expect "#"
send -- "telnet [lrange $argv 0 0]\r"
expect "login:"
send -- "[lrange $argv 1 1]\r"
expect "*:"
send -- "[lrange $argv 2 2]\r"
expect "*]$ "
send -- "history\r"
expect "*]$ "
send -- "exit"
And the shell script has complete path of everything,
#!/bin/bash
# Setiing the Date Varibale
DATE=`date +%d-%m-%Y`
#Make the Result File Null
> /export/home/admin/result.txt
rm /export/home/admin/op*
> /export/home/admin/up
> /export/home/admin/down
# Reading every line in the servers.conf file
cat /home/servers.conf | while read line
do
server=`echo $line | cut -d ':' -f1` # Server name variable
echo "The Server Name" >> result.txt
echo $server >> /export/home/admin/result.txt # Echo the server name to the result filer
echo "-------------------------" >> result.txt
Username=`echo $line | cut -d ':' -f2` # User name
Password=`echo $line | cut -d ':' -f3` # Password for the user
ping -c 1 $server &> /dev/null # Ping the server to check the availability
if [ "$?" -eq 1 ];then # Check the availability of the Server
echo "$server was not pinging!!Please check" >> /export/home/admin/PingFail.txt
if [ "$?" -eq 2 ]; then
echo " " >> /export/home/admin/WrongIPFormat.txt
else
/opt/sfw/bin/expect /home/admin/telExpect.exp $server $Username $Password # Expect Script Called
fi
fi
done >> /export/home/admin/result.txt
#This section We are filering the servers which have Down links
awk '/The server Name/ {n++} {print > f n}' f=/export/home/admin/op /export/home/admin/result.txt;
for i in `ls -lrt /export/home/admin/ | awk '{print $9}' | grep op`;
do
grep down $i
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.