#1  
Old 25th April 2011, 07:19
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 223
Thanks: 11
Thanked 10 Times in 10 Posts
Default I need a crontab script

I need a cron script (either php or shell) that will:

- delete all mp3's in a given directory
- use wget to download the "new" mp3's
- if wget failed (404 or any other reason) email (using sendmail) an error report
- if wget downloaded the files successfully, chmod a remote directory (the remote server is a Mac, so the permissions change at will!), then scp them to the remote server (Mac, so wget doesn't work so well...or I'd run the script on that server)
- if the scp didn't work (permissions, internet connection or any other reason) sendmail an error report

I have everything working except the emailing of the error report....and the chmod.


Here's what I have:

Code:
#!/bin/sh
set -e

cp /backup.mp3 /var/www/showdownloads/XXX/backup.mp3
cd /var/www/showdownloads/XXX
rm *.mp3
wget -nd -r -l1 --no-parent -A.mp3 ftp://XXX:XXXX@XXX.XXX.XXX.XXX/directory/
scp *.mp3 downloads@192.168.2.169:"/Volumes/XXX"
exit
Any ideas?

Thanks!
Reply With Quote
Sponsored Links
  #2  
Old 6th May 2011, 19:12
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 223
Thanks: 11
Thanked 10 Times in 10 Posts
Default

I've finally had some time to work on this again.

I've decided to add error checking (based on exit codes) and email from the code I already have working.

Here's the problem I've run into:

I tried to add the error checking after the scp command (while including a non-working IP addres - - - trying to make it fail). The exit code of the scp command is returning 0 (success) on a "lost connection" attempt.

Here's my code:

Code:
#!/bin/bash
#set -o errexit -o nounset -o xtrace

cd /var/www/weather/

if [ $? -ne 0 ] ; then
SUBJECT="Weather Currents Download Problem Encountered"
# Email To ?
EMAIL="me@me.com"
# Email text/message
EMAILMESSAGE="There was a problem downloading the currents for the weather.  Please check the server."
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/usr/sbin/sendmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
exit 1
fi



wget --no-passive-ftp 'ftp://user:password@remote_ip_address/Current.mp3'

if [ $? -ne 0 ] ; then
SUBJECT="Weather Currents Download Problem Encountered"
# Email To ?
EMAIL="me@me.com"
# Email text/message
EMAILMESSAGE="There was a problem downloading the currents for the weather.  Please check the server."
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/usr/sbin/sendmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
exit 1
fi



echo `scp Current.mp3 root@192.168.2.246:"/Volumes/Big\ Disk/ZWEATHER"`

if [ $? -ne 0 ] ; then
SUBJECT="Weather Currents Download Problem Encountered"
# Email To ?
EMAIL="me@me.com"
# Email text/message
EMAILMESSAGE="There was a problem downloading the currents for the weather.  Please check the server."
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/usr/sbin/sendmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
exit 1
fi





echo `rm Current.mp3`

if [ $? -ne 0 ] ; then
SUBJECT="Weather Currents Download Problem Encountered"
# Email To ?
EMAIL="me@me.com"
# Email text/message
EMAILMESSAGE="There was a problem downloading the currents for the weather.  Please check the server."
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/usr/sbin/sendmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
exit 1
fi

exit
Here's the command run in Putty

Quote:
--2011-05-06 11:00:02-- ftp://user:*password*@remote_ip_address/Current.mp3
=> `Current.mp3'
Connecting to remote_ip_address:21... connected.
Logging in as user... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD not needed.
==> SIZE Current.mp3 ... 19435
==> PORT ... done. ==> RETR Current.mp3 ... done.
Length: 19435 (19K)

100%[======================================>] 19,435 50.0K/s in 0.4s

2011-05-06 11:00:04 (50.0 KB/s) - `Current.mp3' saved [19435]

ssh: connect to host 192.168.2.246 port 22: No route to host
lost connection


server1:~# echo $?
0
server1:~#
192.168.2.246 doesn't exist...and should return an exit code of >0. Why would this return an exit code of 0?
Reply With Quote
  #3  
Old 7th May 2011, 08:25
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 223
Thanks: 11
Thanked 10 Times in 10 Posts
 
Default

I found it...I had copied and pasted a portion of previous code.

The echo on the scp command caused the exit code of 0. After all, it did echo the command.

As soon as I took out the echo and just used scp... everything worked as it should.
Reply With Quote
The Following User Says Thank You to bschultz For This Useful Post:
falko (7th May 2011)
Reply

Bookmarks

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 10:26
Sql ledger using forum.. yurtboy1 General 19 25th December 2010 22:08
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 17:54
Internet Explorer won't connect to my server wctaelectronics Server Operation 10 27th October 2008 22:14
crontab in detail sysconfig Suggest HOWTO 0 4th November 2006 11:38


All times are GMT +2. The time now is 12:11.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.