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 is when I want to set a variable file_name with the name of the file. Here is the code:
I've tried many different things like "set file_name `date +"%F"`.txt" or put the whole `date +"%F"`.txt instead of the variable alltogether. This is just what it currently looks like, I'm hoping the problem is straightforward enough so I don't have to print all the errors I've got over the last hours.
For this code it says this:
[root@backup2 script]# ./script.exp
invalid command name "file_name=`date"
while executing
"file_name=`date +"%F"`.txt"
(file "./script.exp" line 3)
[root@backup2 script]#
Different things I've also tried is calling spawn for that set, also removing all the expect code makes it create a file with the right name and delete it. I've also tried putting the variable declaration infront of the including of expect at the begining but it gives the same problem.
I think I used to have spawn for for the touch command and rm at the end but removed it at some point during the testing. They should probably be put ack, doing so and removing all the send-commands and changing all the calls to file_name to just a string "file_name" makes it work but obviously not creating a file with the current date.
That makes me almost 100% certain, and I can't find how it should be, that I'm doing that file_name= thing wrong...
EDIT: Also witing that date-thing instead of the call to the $file_name sort of works but it creates two files like this:
I know it's a problem wit the darn quotes but I can't figure out which ones it wants, nothing seem to make it execute the date function.
EDIT 2: Never mind, apparently it wats the entire file dedicated to expect, so I just put the expect part in one script and call it in the middle of creating and removing the file in another script.
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)
I was wondering if anyone could provide some assistance. I trying to run an expect script within bash and get the results of a variable called RESULT. I Have tried a few things but none of them have worked. I know that the child process (the expect script) in this instance cannot set a variable... (6 Replies)
I'm trying to make an expect function that will pass through a variable.
/usr/bin/expect<<EOD
spawn su -
expect "Password: "
send "$psswd\r"
expect "#"
send "/etc/init.d/network restart >>$log\r"
expect "#"
send "exit\r"
EOD
The $log passes through but my $psswd fails
I know... (1 Reply)
Hi,
I am writing a script to enter into a list of servers and take the backup of the cronjobs on that servers...
==============================
-bash-3.00$ expect spawn.exp ssh rcdn6-vm59-33
spawn ssh servers1 /CODE]====================
-bash-3.00$ cat spawn.exp
#!/usr/bin/expect
eval... (1 Reply)
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)
Hi All,
I need to frame a unix script to logon to a unix box. The credentials needs to be obtained from a property file on the same location.
I am trying to use 'expect' and 'spawn' command to meet this req.
When I am passing values, these commands are working fine. but when I am trying to... (3 Replies)
SSHing into a machine can take a few seconds, but after I'm in, the commands return quickly. I was wondering if the timeout setting can be changed once I'm logged into the machine. Does anyone know if this can be set on the fly? The problem here is, if I have to set timeout = 10, it'll take 10... (1 Reply)
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)
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)