#1  
Old 11th April 2010, 23:51
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 221
Thanks: 11
Thanked 10 Times in 10 Posts
Default Shell Script If File Exists

I'm trying to write a script to:
1 - download several mp3's
2 - if they downloaded, rename the files
3 - if they didn't download...exit script
4 - if they did download, scp them to another server (I haven't written this part yet...wanted to get the first part working first.)


Here's what I have so far:

Code:
#!/bin/sh
set -e

cd /var/www/testing/

wget -nd -r -l1 --no-parent --no-passive-ftp -A.mp3 'ftp://username:password@IP'

if [ -e /var/www/testing/MIXWX.mp3.1 ];
then
 echo `rm Mix\ 2p.mp3`
 echo `cp MIXWX.mp3.1 Mix\ 2p.mp3`
 echo `rm MIXWX.mp3`
 echo `rm MIXWX.mp3.1`

else
   echo ``

if [ -e /var/www/testing/REALWX.mp3.1 ];
then
   echo `rm Real\ 2p.mp3`
   echo `cp REALWX.mp3.1 Real\ 2p.mp3`
   echo `rm REALWX.mp3`
   echo `rm REALWX.mp3.1`

else
   echo ``

if [ -e /var/www/testing/TALKWX.mp3.1 ];
then
  echo `rm Talk\ 2p.mp3`
  echo `cp TALKWX.mp3.1 Talk\ 2p.mp3`
  echo `rm TALKWX.mp3`
  echo `rm TALKWX.mp3.1`

else
   echo ``


if [ -e /var/www/testing/WMIS.mp3.1 ];
then
  echo `rm Talk\ 2p.mp3`
  echo `cp WMIS.mp3.1 WMIS\ 2p.mp3`
  echo `rm WMIS.mp3`
  echo `rm WMIS.mp3.1`

else
   echo ``

if [ -e /var/www/testing/Current.mp3 ];
then
  echo `rm Current.mp3`
else
   echo ``

exit
I'm getting this error:

Quote:
Line 56: syntax error: unexpected end of file
Any ideas what I'm doing wrong?

Thanks!
Reply With Quote
Sponsored Links
  #2  
Old 12th April 2010, 11:57
Mark_NL Mark_NL is offline
Senior Member
 
Join Date: Sep 2008
Location: The Netherlands
Posts: 912
Thanks: 12
Thanked 100 Times in 96 Posts
Default

why are you echo ``-ing in every else?
Reply With Quote
  #3  
Old 12th April 2010, 13:53
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 221
Thanks: 11
Thanked 10 Times in 10 Posts
Default

don't delete, don't rename, don't do anything if the file didn't download
Reply With Quote
  #4  
Old 12th April 2010, 14:47
Mark_NL Mark_NL is offline
Senior Member
 
Join Date: Sep 2008
Location: The Netherlands
Posts: 912
Thanks: 12
Thanked 100 Times in 96 Posts
Default

so that would be the same as not defining it at all ;-)

Code:
#!/bin/bash

cd /var/www/testing/

wget -nd -r -l1 --no-parent --no-passive-ftp -A.mp3 'ftp://username:password@IP'

if [ -e MIXWX.mp3.1 ];
then
 echo `rm Mix_2p.mp3`
 echo `cp MIXWX.mp3.1 Mix_2p.mp3`
 echo `rm MIXWX.mp3`
 echo `rm MIXWX.mp3.1`
fi

if [ -e REALWX.mp3.1 ];
then
   echo `rm Real_2p.mp3`
   echo `cp REALWX.mp3.1 Real_2p.mp3`
   echo `rm REALWX.mp3`
   echo `rm REALWX.mp3.1`
fi

if [ -e TALKWX.mp3.1 ];
then
  echo `rm Talk_2p.mp3`
  echo `cp TALKWX.mp3.1 Talk_2p.mp3`
  echo `rm TALKWX.mp3`
  echo `rm TALKWX.mp3.1`
fi

if [ -e WMIS.mp3.1 ];
then
  echo `rm Talk_2p.mp3`
  echo `cp WMIS.mp3.1 WMIS_2p.mp3`
  echo `rm WMIS.mp3`
  echo `rm WMIS.mp3.1`
fi

if [ -e Current.mp3 ];
then
  echo `rm Current.mp3`
fi

exit
Reply With Quote
The Following User Says Thank You to Mark_NL For This Useful Post:
bschultz (12th April 2010)
  #5  
Old 12th April 2010, 16:19
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 221
Thanks: 11
Thanked 10 Times in 10 Posts
Default

That worked great...Thanks!

Now, on to work on the scp part.
Reply With Quote
  #6  
Old 30th April 2010, 20:03
bschultz bschultz is offline
Senior Member
 
Join Date: Jul 2006
Posts: 221
Thanks: 11
Thanked 10 Times in 10 Posts
 
Default

Is there a way to write this so that it retries to download the file after a minute if the remote server isn't reachable?
Reply With Quote
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
Postfix delivery problem erebus Installation/Configuration 8 29th July 2014 20:17
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
Email problem 'Cannot set my user or group id.' (using ISPConfig 3 + OpenSuSE 11.2) urosm Installation/Configuration 5 19th June 2010 22:41
libWand.so.10 error Taxick Installation/Configuration 8 3rd May 2009 01:27
Systemimager (rsync) doesn't copy all comedit HOWTO-Related Questions 11 19th January 2007 17:17


All times are GMT +2. The time now is 04:45.


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