[SOLVED]bash script if file exists statement not wroking
im working on some bash scripts that run on logon/off and backup the resume data for uTorrent so that it automatically copies the resume data to the other OS i boot into and resumes the torrents where i left off ( i have a quad boot :D). im currently working on the Ubuntu on/off scripts. i have Ubuntu 12.04.
the problem is that i cant get the if file exists part to work:
Code:
if [ -f "/opt/utorrent-server-v3_0/resume.dat" ];
i know "/opt/utorrent-server-v3_0/resume.dat" exists as i get command not found in terminal. It always goes to the else, so im pretty sure something is wrong with the file exists part. what do you guys think?
Thanks!
Code:
if [ -f "/opt/utorrent-server-v3_0/resume.dat" ]; #if it exists
then
#copy currrent resume to the Data partition
cp "/opt/utorrent-server-v3_0/resume.dat" "/media/Data/uTorrentBack"
cp "/opt/utorrent-server-v3_0/resume.dat.old" "/media/Data/uTorrentBack"
#copy all .torrent files to the Data partition
cp "/opt/utorrent-server-v3_0/"*.torrent "/media/Data/uTorrentBack"
#else
zenity --info --text="uTorrent resume files not found! \n uTorrent not installed?" #make a pop-up alert!
fi
PS: i couldn't post in the dev + program forum below, sorry :(
Re: bash script if file exists statement not wroking
Hi sirbow2.
A few ideas:
If you don't have permissions to access the file (you can't 'ls' it), the 'if' test will fail.
-f is to test for a regular file. What kind of file is resume.dat?
You can also try '-e' as it only cares about if it exits (no problems with directories, devices, etc).
Hope it helps. Let us know how it goes.
Regards.
Re: bash script if file exists statement not wroking
In your above code snippet, you have the 'else' commented out. Is it that way in your script? If so, that's why the 'else' is executing; there really is not 'else' in that script :D
Re: bash script if file exists statement not wroking
haha, wow, sorry about that. the # would be it.
works great :P