Hi everyone,
i'm having a little trouble wih my first shell script ever.
So the point of that script is to:
-Archive Zip files in a directory
-Remove txt files from that directory
-connect through sftp and a rsa key to a remote server
-download a couple of files
-unzip downloaded files
I glanced information here and there and tried to make a script out of it so here's what i've got so far
Quote:
#!/bin/sh
########## CONFIG
INBOX_DIR=/home/data-exchange/inbox
REMOTE_DIR=outgoing/
DATA_DIR_1=users/
DATA_DIR_2=games/
##### ARCHIVE
mv $INBOX_DIR/*.zip $INBOX_DIR/archive
rm $INBOX_DIR/*.txt
##### SFTP GET
sftp
myuser@data.myserver.com -P22 <<EOF
cd $REMOTE_DIR
mget $DATA_DIR_1/*.zip $INBOX_DIR
mget $DATA_DIR_2/*.zip $INBOX_DIR
bye
EOF
##### DATA EXTRACT
cd $INBOX_DIR
ls -1 *.zip > filelist
for filename in `cat filelist`
do
unzip $filename
done
rm filelist
So i have a couple problems :
-First of all, i'd like to test the presence of any .txt file before i remove it.Caus' i'd get an error if none exist
-Second, i don't know why, the last part ( #DATA EXTRACT ) is executed before the second part ( #SFTP GET ) , so it doesn't find any files that need decompression ... and my files arent unzipped
-Third, but this is more general, i'd like to make my own output out of this instead of the ugly regular output that all those commands would give me, so any kind of precise link would be greatly appriciated.
Thanks for your time !