expect script not running in cron "Urgent"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect script not running in cron "Urgent"
# 1  
Old 10-12-2012
expect script not running in cron "Urgent"

I wrote a script to download the files from sftp location to local. while running the script manually its working fine. when i schedule the same in cron its not working.... SmilieSmilie

here is the script:

Code:
#!/bin/bash

PATH=/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib/jvm/jre-1.6.0-openjdk.x86_64:/usr/local/hadoop-0.20.2/bin:/usr/local/pig-0.6.0/bin:/home/ganga/bin

username=ganga
password=ganga1#
server=192.168.151.25
download_dir=/ganga/home/logs/
mkdir $download_dir

expect -c "
             # exp_internal 1 # uncomment for debugging
        spawn /usr/bin/scp "$username$server:/home/ganga/DYNAMIC/DELETES/*.log" $download_dir
             expect {
               "*Password:*" { send $password\r\n; interact }
               eof { exit }
             }
             exit
             "

cron_log:

Code:
Oct 12 11:13:01 hostname CROND[8304]: (ganga) CMD (/bin/sh /home/ganga/download.sh)

OS:

Redhat-linux 6.2

please help on this

Thanks,
Ganga

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 10-12-2012 at 07:37 AM..
# 2  
Old 10-12-2012
Hi Ganga,

This is probably because there are some environmental variables missing from the script, I'd be tempted to test it quickly by adding a line which loads the environment to test it try adding the following at the begining of your script.

Code:
source /etc/profile
source ~$username/.bash_profile

That is assuming I have the correct shells.

You can then identify which variables are missing and fix your script.

Regards

Dave
# 3  
Old 10-18-2012
Hi Dave,

Thanks for reply.

I have tried as u told still its not working.
I trid at command like sh <script name > |at now + 2 mnts. its working manually.

i wrote into another file like below:

Code:
$ cat >file.sh
echo `sh <script name > |at now + 2 mnts`

i scheduled in cron
Code:
10 20 * * * /bin/sh /home/ganga/file.sh

it is fired and scheduled as at job.

but, again i am facing the same problem. I didn't understand what is going here. Smilie Smilie

Regards,

Gangadhar.

Last edited by Scott; 10-18-2012 at 01:49 PM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

3. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

Ladies & Gents, Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all. Many thanks in advance. U guys have honestly earned my... (1 Reply)
Discussion started by: Hiroshi
1 Replies

4. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

5. Shell Programming and Scripting

Expect Script - Variables are Empty immediately after "Setting" Them?

Hello All, I have embedded some expect code inside a Bash script I'm writing, but for some reason any variable I 'set' to something is showing as empty immediately on the next line... I haven't run into this problem before so I'm not sure what it could be...? I'm guessing it has something to... (4 Replies)
Discussion started by: mrm5102
4 Replies

6. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

7. Shell Programming and Scripting

exec perl in expect script yields "invalid command"

I'm trying to execute something like this: exec perl -i -pe 's/\015/\012/g' '${file}' in my expect script and I get: error "invalid command name \"perl\". however, if I run perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt" directly in my terminal, it runs fine. I'm an... (4 Replies)
Discussion started by: dpouliot
4 Replies

8. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

9. UNIX for Dummies Questions & Answers

running command "top" in cron

hi all, i would like to collect stat. about the cpu usage every 30 mins so, I set up the cron job sth like 0,30 * * * * * /usr/bin/top -d 1 >> $STAT i know cron doesn't have a TERM output, so error occurs. any ideas or work around for this?? many thanks (3 Replies)
Discussion started by: freddy1228
3 Replies

10. Shell Programming and Scripting

Running "wall" command from cron

Hello, Ive written a little script that broadcasts a message if certain criteria are met. The script works fine when I run it. I entered it in the crontab to run every hour on the hour. The script executes, but the wall command doesnt seem to be executing correctly. I only have this... (1 Reply)
Discussion started by: xadamz23
1 Replies
Login or Register to Ask a Question