1hoschi
asked on
shellscript ftp filename as variable
Hi
I need a shell script to download a tar file from a server daily and extract it to a specified folder. the problem i have is that the name of the file changes unregularly and i dont know how to get the name of the downloaded file as a value in my script to extract the file. does anyone have got an idea how to handle this?
heres some code:
#!/bin/sh
HOST='ftp.url.com'
USER='user'
PASSWD='pass'
FILE='*.tar' //there is only one tar-file
cd /usr/local/folder
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
get $FILE
quit
END_SCRIPT
tar xvf FILENAME <------ how can i get this in here
thanx a lot
I need a shell script to download a tar file from a server daily and extract it to a specified folder. the problem i have is that the name of the file changes unregularly and i dont know how to get the name of the downloaded file as a value in my script to extract the file. does anyone have got an idea how to handle this?
heres some code:
#!/bin/sh
HOST='ftp.url.com'
USER='user'
PASSWD='pass'
FILE='*.tar' //there is only one tar-file
cd /usr/local/folder
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
get $FILE
quit
END_SCRIPT
tar xvf FILENAME <------ how can i get this in here
thanx a lot
Agreed with HamdyHassan to use mget, modify your script to:
#!/bin/sh
HOST='ftp.url.com'
USER='user'
PASSWD='pass'
FILE='*.tar' #there is only one tar-file
cd /usr/local/folder
ftp -inv $HOST <<END_SCRIPT
user $USER $PASSWD
binary
mget $FILE
quit
END_SCRIPT
#To untar the files, you need to do:
for f in *.tar
do
echo "extracting $f ...."
tar xvf $f
done
exit
exit
#!/bin/sh
HOST='ftp.url.com'
USER='user'
PASSWD='pass'
FILE='*.tar' #there is only one tar-file
cd /usr/local/folder
ftp -inv $HOST <<END_SCRIPT
user $USER $PASSWD
binary
mget $FILE
quit
END_SCRIPT
#To untar the files, you need to do:
for f in *.tar
do
echo "extracting $f ...."
tar xvf $f
done
exit
exit
ASKER
thanks alot, but with that you will extract all tar files in the target folder, but i only want to have the downloaded to be extracted. there is only one tar on the ftp but there may be many on the local folder.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use mget *.tar
ftp -i -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
mget *.tar