LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 03-15-2013, 02:16 PM   #1
jaipsharma
LQ Newbie
 
Registered: Jun 2010
Posts: 8

Rep: Reputation: 0
Shell script using expect to login to couple of remote servers and read "crontab -l"


I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP address. it should also create a summary at the end with the status if any server unable to login with error.

Please help.
 
Old 03-15-2013, 03:24 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,137

Rep: Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457
Quote:
Originally Posted by jaipsharma View Post
I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP address. it should also create a summary at the end with the status if any server unable to login with error.

Please help.
Help with WHAT?? You haven't posted a problem/question...you've only told us that you want a shell script to do something. If that's the case, then YOU need to write one. We will be glad to HELP you if you have a specific problem...so post your code, sample input/output files, and what happens when you run it/where you're stuck, and we'll assist. But we are NOT going to write your scripts for you.

Otherwise, you can easily find THOUSANDS of bash scripting tutorials on Google...there's even one in my post signature. Read/follow them.
 
Old 03-16-2013, 11:47 AM   #3
jaipsharma
LQ Newbie
 
Registered: Jun 2010
Posts: 8

Original Poster
Rep: Reputation: 0
I tried writing the script & outputs as file hostname.crontab & hostname.rc.local & disk.status and summary of success and failure. I provided a input as list of hostname from a file.

for i in `cat hostname`
do
expect -c "
spawn ssh -t username@$i \"cat /etc/rc.local\" >> $i.rc.local
spawn ssh -t username@$i \"crontab -l -u root\" >> $i.crontab
spawn ssh -t username@$i \"df -h\" >> $i.disk.status
expect {
-re \".*Are.*.*yes.*no.*\" {
send \"yes\n\"
exp_continue
}
}
expect {
"?assword:" { send -- \"password\r\"; interact }
}
"
done

if someone can help me fine tuning.

Last edited by jaipsharma; 03-16-2013 at 11:52 AM.
 
Old 03-16-2013, 04:59 PM   #4
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,137

Rep: Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457Reputation: 2457
Quote:
Originally Posted by jaipsharma View Post
I tried writing the script & outputs as file hostname.crontab & hostname.rc.local & disk.status and summary of success and failure. I provided a input as list of hostname from a file.
Code:
for i in `cat hostname`
do
expect -c "
spawn ssh -t username@$i \"cat /etc/rc.local\" >> $i.rc.local
spawn ssh -t username@$i \"crontab -l -u root\" >> $i.crontab
spawn ssh -t username@$i \"df -h\" >> $i.disk.status
expect {
-re \".*Are.*.*yes.*no.*\" {
send \"yes\n\"
exp_continue
}
}
expect {
"?assword:" { send -- \"password\r\"; interact }
}
"
done
if someone can help me fine tuning.
Sure, now that we know what the code is, can you tell us what problem(s) you're having? We can't guess as to what you need.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash says "no such file or directory" when crontab runs the shell script ymnoor21 Linux - Newbie 16 03-23-2012 11:18 AM
"URGENT"How can i execute shell script from a remote server ? amit.giri Linux - Newbie 9 10-05-2009 09:15 AM
My "expect" script is not working... Won't "send" commands... edomingox Programming 4 04-02-2009 03:25 PM
shell script to mount samba share with " " in the remote path dohpaz Programming 2 10-20-2006 02:18 PM


All times are GMT -5. The time now is 02:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration