LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-01-2013, 04:26 AM   #1
cpjain
LQ Newbie
 
Registered: Jan 2013
Posts: 1

Rep: Reputation: Disabled
wget -O creates a empty file on failure


Hi All,

I am trying to check in the if condition that "some file" exists in the repository or not like below:

if (wget -O /path/ $REPO_URL); then
do operation
fi

my purpose is, if the file is present then do wget and perform some operation on that.

this is working well if the file is present however if it is not present in the repository wget creates an empty file.

how can i prevent this and what are my options?

Regards,
Chetan Jain.
 
Old 02-01-2013, 08:26 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
You can check the return value of 'wget':

Code:
wget -O /path/ $REPO_URL
if [[ $? -eq 0 ]]; then
   do stuff
fi
 
Old 02-01-2013, 08:37 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
...next to the return value of wget you can also check the size of the output file (see 'man test' and increase mana for using 'mktemp'):
Code:
goNoGo() { _TMPFILE=`mktemp -p /tmp wget.XXXXXXXXXX` && {
wget -q $1 -O > "${_TMPFILE}"; RETVAL=$?
[ $RETVAL -ne 0 ] && return 1
[ -s "${_TMPFILE}" ] && return 1
 rm -f "${_TMPFILE}"; } 
}
Use like:
Code:
goNoGo $REPO_URL && do operation
*Caveats: checking wget exists (subst cURL, elinks -dump, etc, etc) plus the result could still be a malformed repo file...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
wget downloads empty pages ted_chou12 Linux - Newbie 1 04-05-2011 02:55 PM
[SOLVED] wget failure on my system Ajit Gunge Linux - Newbie 5 10-07-2010 06:57 AM
[SOLVED] Cron - mysqldump job creates an empty sql file novice32 Linux - Newbie 5 04-17-2010 01:12 PM
Kubuntu creates empty folders in my home dir bhert Ubuntu 3 06-26-2008 01:59 PM
aplay -l > message,txt creates empty file milindlokde Programming 5 06-24-2007 02:46 PM


All times are GMT -5. The time now is 08:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration