LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-22-2007, 04:21 PM   #1
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Rep: Reputation: 31
Unhappy shell script help


I wrote this script to automate a daily FTP download with cron job. The script work when I run it manually. But, it won't execute anything from gpg portion of the script when it's run by cron job. Any suggestions?

Here is my sript:

#!/bin/bash
cd /var/tmp/BOA_Downloads
HOST="ftp4.bankofamerica.com"
USER="FTP_Username"
PASSWD="FTP_Password"
FILE="BISTATE"
DATE=`date +%m%d%y`
ftp -n -v $HOST << EOT
binary
user $USER $PASSWD
prompt
mget $FILE
bye
bye
EOT
mv $FILE $FILE$DATE
echo m3tr0b0@ | gpg --passphrase m3tr0b0@ --output /var/tmp/BOA_Decrypt/$FILE$DATE --decrypt $FILE$DATE
cp /var/tmp/BOA_Decrypt/$FILE$DATE /var/tmp/$FILE$DATE.dat
scp /var/tmp/BOA_Decrypt/$FILE$DATE root@bsdacore10:/var/tmp/BOA_Decrypt/

Please help.....John
 
Old 08-22-2007, 04:58 PM   #2
cgjones
Member
 
Registered: Nov 2005
Location: Central New York
Distribution: Ubuntu
Posts: 405

Rep: Reputation: 31
Are you using the system crontab, or the crontab of a specific user?
 
Old 08-22-2007, 05:00 PM   #3
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Original Poster
Rep: Reputation: 31
crontab under root
 
Old 08-22-2007, 05:14 PM   #4
cgjones
Member
 
Registered: Nov 2005
Location: Central New York
Distribution: Ubuntu
Posts: 405

Rep: Reputation: 31
I assume that when you run the script manually, you run it as your normal user?
 
Old 08-22-2007, 06:03 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
How about splitting up stuff? I mean the grabbing and distributing stuff can be run unattended from a cronjob. Then you can do the decrypting when you're at the console. Putting the PGP passphrase in a script is a hazard itself and defeats any encryption purposes (IMNSHO).
 
Old 08-23-2007, 11:44 PM   #6
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Original Poster
Rep: Reputation: 31
cgjones,

I'm actually running this script as root.

unSpawn,

unfortunately, this is a daily job and our business unit want this run automatically. I know run gpg passphrase in a script is not a great idea. But, this server is sitting inside 2 layers of Cisco firewall and I have iptables running on it.
 
Old 08-24-2007, 03:41 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Probably from crontab, it can't find the PATH to gpg command, since by default the crontab environment has a very limited PATH. You can check this by simply executing (from crontab) a
Code:
echo $PATH > somefile
Also you can check with the mail command, if you have received some error message from the crontab job. All this stuff on linux can be set in the crontab file. See
Code:
man 5 crontab
for details (look for setting MAILTO and PATH variables).
 
Old 08-29-2007, 09:54 PM   #8
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Original Poster
Rep: Reputation: 31
colucix,

I put in the whole path and still no luck with the job. I'm not getting any error log either.
 
Old 08-30-2007, 08:06 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What exactly does not work? Can't you find any of the created/copied/s-copied files? As a further debug option you can add -x to the first line
Code:
#!/bin/bash -x
This will give the execution trace. Then redirect standard error and standard output to a file directly in the crontab job, e.g
Code:
05 15 * * * $HOME/theScript.sh > $HOME/logfile 2>&1
You can post the output here, if you don't mind. Cheers!
 
Old 08-30-2007, 08:37 AM   #10
nan0meter
Member
 
Registered: Aug 2007
Location: The Netherlands
Distribution: Fedora 7 x86_64
Posts: 119

Rep: Reputation: 15
Code:
#!/bin/bash
HOST="ftp4.bankofamerica.com"
USER="FTP_Username"
PASSWD="FTP_Password"
FILE="BISTATE"
DATE=`date +%m%d%y`
LOG="/var/log/boa_cron.log"

echo "[$DATE] Moving to directory: /var/tmp/BOA_Downloads" > $LOG

cd /var/tmp/BOA_Downloads

echo "[$DATE] Moving to directory /var/tmp/BOA_Downloads: done" > $LOG
echo "[$DATE] Downloading files from $HOST" > $LOG

ftp -n -v $HOST << EOT
binary
user $USER $PASSWD
prompt
mget $FILE
bye
bye
EOT

echo "[$DATE] Downloading file from $HOST: done" > $LOG
echo "[$DATE] Moving file..." > $LOG

mv $FILE $FILE$DATE

echo "[$DATE] Moving file: done" > $LOG

echo "[$DATE] Decrypting..." > $LOG
echo m3tr0b0@ | gpg --passphrase m3tr0b0@ --output /var/tmp/BOA_Decrypt/$FILE$DATE --decrypt $FILE$DATE

echo "[$DATE] Decrypting: done" > $LOG
echo "[$DATE] Copying decrypted file..." > $LOG

cp /var/tmp/BOA_Decrypt/$FILE$DATE /var/tmp/$FILE$DATE.dat

echo "[$DATE] Copying decrypted file: done" > $LOG
echo "[$DATE] Copying decrypted file to root@bsdacore10" > $LOG

scp /var/tmp/BOA_Decrypt/$FILE$DATE root@bsdacore10:/var/tmp/BOA_Decrypt/

echo "[$DATE] Copying decrypted file: done" > $LOG
echo " --- " > $LOG
As you can see i modified the code with debug messages that he logs in $LOG (/var/log/boa_cron.log). Be sure to run this as root else you might not create the log files.

Now try to execute it in cron and see if it puts any output in /var/log/boa_cron.log. If it doesn't then it doesn't execute the script (properly).

As posted above, you can also try to run this script with bash -x but i didn't include it in this one.

Last edited by nan0meter; 08-30-2007 at 08:39 AM.
 
Old 09-06-2007, 04:58 PM   #11
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Original Poster
Rep: Reputation: 31
thanks nan0meter. I will modified my script and see what the log have to said tomorrow.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration