Problems with expect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with expect
# 1  
Old 05-22-2013
Problems with expect

Hi,

I am writing a script to enter into a list of servers and take the backup of the cronjobs on that servers...

==============================
[CODE]-bash-3.00$ expect spawn.exp ssh rcdn6-vm59-33
spawn ssh servers1 /CODE]====================
Code:
-bash-3.00$ cat spawn.exp
#!/usr/bin/expect
eval spawn $argv
expect "$"
send "crontab -l >> /tmp/cronjob"
expect "$"

===================================

***Can you suggest me the commands in the spawn.exp which needs to be used for a graceful exit after executing the commands.

I am calling spawn.exp from other script where i filter all the hostnames from the file as given below.
============================================
Code:
-bash-3.00$ cat main.sh
#!/bin/bash
FILENAME=servers.txt
count=0
hostnam=`hostname`
echo $hostnam
cat $FILENAME | while read LINE
do
let count++
echo "$count $LINE"
expect -f spawn.exp ssh $LINE
done

-bash-3.00$

======================================================

---------- Post updated at 08:05 AM ---------- Previous update was at 04:27 AM ----------

I got it solved by using this script....i think my prompt wasn't correct..now its working fine..Smilie

Code:
-bash-3.00$ cat spawn.exp
#!/usr/bin/expect
set prompt "(%|#|\\$|%\]) $"
eval spawn $argv
expect -re "$prompt"
send "sleep 5\r"
expect -re "$prompt"
send "crontab -l >> /tmp/cronjob\r"
expect -re "$prompt"
send  "exit\r"


Last edited by satishkumar432; 07-18-2013 at 08:38 PM.. Reason: Please use code tags for data and code samples
# 2  
Old 05-24-2013
Add a cron job to each server, to have it save the cron info periodically, Date-time in file name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Shell Programming and Scripting

Problems with expect and sftp in bash

I'm having trouble with some automated sftp pulls. I'm using expect inside bash scripts and spawning SFTP. Some times the expect seems bog down. I have tried to put sleeps in my code to give everything time to work before I move on to next step but I till continue to get issues. For example when... (2 Replies)
Discussion started by: gosteen
2 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

Expect script Execution Problems .. Help!!!

Hi Guys, I am writing the expect script which take input from the txt file and check whether that file is present over the Sftp or not.If yes then delete other wise check the next one.. I am able to do comparison online for single file... Please also note still i didn't try to implement... (1 Reply)
Discussion started by: hackerdilli
1 Replies

5. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

6. Shell Programming and Scripting

Problems with expect and set variables

I'm writing a script that'll send a time-stamp to my backup server. I create a file with the name of the current date, send it to my server with scp and rm the file from the local computer. Individually these commands work fine and with a set name the expect scripts also work fine. The problem... (0 Replies)
Discussion started by: Ktesh564
0 Replies

7. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

8. Shell Programming and Scripting

problems installing expect utilty

Hi all, I am trying to install expect utility on RHEL 5. It is showing that we also need to install tcl also in order to run it. I have downloaded expect from Tucows Tucows Download - Download Expect 5.32.1 and tcl from SourceForge.net: Downloading ... Can someone please tell me... (5 Replies)
Discussion started by: vikas027
5 Replies

9. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

10. Shell Programming and Scripting

Expect script with file input problems

Hello, I am trying to write an expect script that will ssh into a large number of Cisco routers and add some commands via the cli. The script I wrote works great for one host however I have over 350 routers that this needs to be added to. The problem is I cannot get the script to read the file of... (1 Reply)
Discussion started by: meberline
1 Replies
Login or Register to Ask a Question