LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Shell script using expect to login to couple of remote servers and read "crontab -l" (https://www.linuxquestions.org/questions/linux-networking-3/shell-script-using-expect-to-login-to-couple-of-remote-servers-and-read-crontab-l-4175454230/)

jaipsharma 03-15-2013 02:16 PM

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.

TB0ne 03-15-2013 03:24 PM

Quote:

Originally Posted by jaipsharma (Post 4912476)
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.

jaipsharma 03-16-2013 11:47 AM

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.

TB0ne 03-16-2013 04:59 PM

Quote:

Originally Posted by jaipsharma (Post 4912935)
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.


All times are GMT -5. The time now is 08:12 AM.