First post here and I belive this is where the very basic questions go, so.
I have a script where I check if a directory exists. If not, then it creates the directory, changes into the directory and initiates an sftp session to download files.
My only concern with it is on the last read (read answer) it actually displays the option I chose which is no big deal and thinking about this, I really don't care that it does this.
Well, I am wondering if someone can take a look at it and tell me how I can improve it or make suggestions?
Code:
#!/bin/bash
HOME=/home/user
sftp () {
/usr/bin/sftp user@sftp.server.com
}
makedir () {
mkdir $HOME/$number
}
echo -n "enter the last four digits of the case number "
read number
if [ ! -d $HOME/$number ]; then
echo "directory does not exist, now creating directory..."
makedir;
cd "$HOME/$number"
sftp;
else
echo "directory exists..."
echo "do you want to initiate sftp y/n"
read answer
if [[ $answer == [yY] ]];then
cd "$HOME/$number"
sftp;
else
echo "goodbye..."
exit 1
fi
fi
I just noticed that when testing with FTP the script works as I am prompt to enter my credentials. However, whilst using sftp it just loops and I am somewhat lost as to why it does this?
I determined it sitting in a loop by running bash - x script.sh
and all I saw was the lines sftp sftp.server.com over and over again.
Will continue troubleshooting this issue.
I corrected the issue above by providing the full path to sftp.
Thank you!