Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-15-2013, 03:16 PM
|
#1
|
LQ Newbie
Registered: Jun 2010
Posts: 8
Rep:
|
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.
|
|
|
03-15-2013, 04:24 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,331
|
Quote:
Originally Posted by jaipsharma
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.
|
|
|
03-16-2013, 12:47 PM
|
#3
|
LQ Newbie
Registered: Jun 2010
Posts: 8
Original Poster
Rep:
|
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 12:52 PM.
|
|
|
03-16-2013, 05:59 PM
|
#4
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,331
|
Quote:
Originally Posted by jaipsharma
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 09:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|