LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-11-2020, 05:56 PM   #1
orangepeel190
Member
 
Registered: Aug 2016
Posts: 69

Rep: Reputation: Disabled
Script to check files - different file names


Hi All,

I was wondering if someone would be able to check my script....

I am wishing to download a file from the mater website, if that website or file is not present, it will redirect to a backup server - and try and source the file from there

Bash Script....


Code:
/usr/bin/wget https://drive.google.com/drive/path/here/$FILE1 || \
/usr/bin/wget http://www.second.webserver/$FILE2 \\ error 1

if [ -f $FILE1 ]; then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
else

[ -f $FILE2 ] then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

exit 0;;
The Google address is proving temperamental (must be missing something in the URL), but I am having issues trying to checking which File was downloaded in the IF/FI statement so that when whichever file was downloaded - the correct statement was displayed

Thought to give it a try, but I am going around in circles to find out what is wrong and missing.

Would curl be a better option than wget for the download?

Code:
/usr/bin/curl -sSkLo $FILE1 https://drive.google.com/drive/path/here/$FILE1 || \
/usr/bin/curl -sSkLo $FILE2 http://www.second.webserver/$FILE2 || error 1

if [ -f $FILE1 ]; then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
else

[ -f $FILE2 ] then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

exit 0;;
What part is fowling up?

Last edited by orangepeel190; 07-11-2020 at 06:02 PM.
 
Old 07-11-2020, 06:23 PM   #2
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by orangepeel190 View Post
Hi All,

I was wondering if someone would be able to check my script....

I am wishing to download a file from the mater website, if that website or file is not present, it will redirect to a backup server - and try and source the file from there

Bash Script....


Code:
/usr/bin/wget https://drive.google.com/drive/path/here/$FILE1 || \
/usr/bin/wget http://www.second.webserver/$FILE2 \\ error 1

if [ -f $FILE1 ]; then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
else

[ -f $FILE2 ] then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

exit 0;;
The Google address is proving temperamental (must be missing something in the URL), but I am having issues trying to checking which File was downloaded in the IF/FI statement so that when whichever file was downloaded - the correct statement was displayed

Thought to give it a try, but I am going around in circles to find out what is wrong and missing.

Would curl be a better option than wget for the download?

Code:
/usr/bin/curl -sSkLo $FILE1 https://drive.google.com/drive/path/here/$FILE1 || \
/usr/bin/curl -sSkLo $FILE2 http://www.second.webserver/$FILE2 || error 1

if [ -f $FILE1 ]; then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
else

[ -f $FILE2 ] then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

exit 0;;
What part is fowling up?
You can't add a condition to an else statement, because else is the 'catch all' statement.
Try elif [ CONDITION ].

You can use curl if you want to, but you will need to manually specify the output file, or use the -O option. Otherwise, it will try to print to stdout.
 
Old 07-11-2020, 06:40 PM   #3
orangepeel190
Member
 
Registered: Aug 2016
Posts: 69

Original Poster
Rep: Reputation: Disabled
Opps .... Sorry - the curl statement should be:

/usr/bin/curl -SkL https://drive.google.com/drive/path/here/$FILE1 -o $FILE1|| \
/usr/bin/curl -SkL http://www.second.webserver/$FILE2 -o $FILE2|| error 1

That should work better ?

Ill give the elif in the middle of the condition statement

Code:
if [ -f $FILE1 ]
then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
elif 
[ -f $FILE2 ]
then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

Appreciate your reply and helping me resolve the issue ....

That look a little better?

Last edited by orangepeel190; 07-11-2020 at 06:59 PM.
 
Old 07-11-2020, 07:35 PM   #4
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by orangepeel190 View Post
Opps .... Sorry - the curl statement should be:

/usr/bin/curl -SkL https://drive.google.com/drive/path/here/$FILE1 -o $FILE1|| \
/usr/bin/curl -SkL http://www.second.webserver/$FILE2 -o $FILE2|| error 1

That should work better ?

Ill give the elif in the middle of the condition statement

Code:
if [ -f $FILE1 ]
then
echo ".... SUCCESS !!! $FILE1 downloaded from Master Site....."
elif 
[ -f $FILE2 ]
then
echo ".... SUCCESS !!! $FILE2 downloaded from backup site....."
fi

Appreciate your reply and helping me resolve the issue ....

That look a little better?
You may want to add an else statement to handle the event of neither file being downloaded. Also, curl has the -O (capital letter O) flag, which will output to the file name specified in the URL. So you don't need to write -o $FILE1, just curl -SkLO 'URL'.
 
1 members found this post helpful.
Old 07-12-2020, 12:01 AM   #5
orangepeel190
Member
 
Registered: Aug 2016
Posts: 69

Original Poster
Rep: Reputation: Disabled
Fantastic!

Working a treat now..... Much appreciated!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Burning with cdw: file names are too long, try "Long Joliet file names" lucmove Linux - Software 3 02-21-2017 06:06 AM
Bash: bash file names are different than openbox trash file names whatthefunk Programming 4 02-15-2011 01:52 AM
copying multiple different files in different directories with identical file names nickleus Linux - Software 4 03-09-2006 01:25 PM
Different DNS name servers for different domain names? skaralic Linux - Networking 1 12-09-2005 04:19 PM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:39 AM.

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