this is my script and as you can see in the screenshot i attach its not deleting the directory in the source folder
#!/bin/bash
cd /vol/cha-work/_ARCHIVE/to_be_archived/audio/robert_test
temp=/mnt/robert_test/temp
dest=/vol/cha-archive/audio
echo "is this archive for an audio tar press (t) or an audio directory press (d)"
read option
case $option in
d)
echo "please specify full path to directory you want to be made into a tar"
read -e dir
# echo "please enter ID number ie ID1234"
# read id
# echo "please specify where you want the tar file to be stored"
# read -e dest
cd "$dir"
base=$(basename "$dir")
echo -e "create "$base" into "$base".tar\n"
echo -e "move "$base".tar to "$dest"\n"
# echo -e "remove "$base".tar from "$dir"\n"
echo -e "remove "$base" from "$dir"\n"
echo "is this information correct, press (y) or press (n)"
read correct
case $correct in
y)
echo "the script will now continue";;
n)
echo "please re-run the script inputting correct details"
exit;;
*)
echo "invalid selection, please re-run the script"
exit;;
esac
date >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo "" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
# echo -e ""$id"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e ""$dir"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e "how many files = `find . -type f | wc -l`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e "size of directory = `du -sh`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
ls -R >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
cd ..
if ! cp -R "$base" "$temp" ; then
echo "something went wrong rsync command, please do manually"
exit
fi
cd "$temp"
if ! tar -cf "$dest"/"$base".tar "$base" ; then
echo "something went wrong creating the tar, please do manually"
exit
fi
if ! rm -rf "$temp"/"$base" ; then
echo "something went wrong with the rm -rf command, please do manually"
exit
fi
if ! rm -rf "$dir" ; then
echo "something went wrong with the rm -rf command, please do manually"
exit
fi
;;
*)
echo "invalid selection, please re-run the script"
exit;;
esac
where it says please enter the directory i have entered -
testdirtobearchived
and as you can see it creates the tar file fine and stores it in the destination folder but it doesnt remove the directory in robert_test
First: screen shots don't help way as much as do execution logs posted in text form, e.g. created by setting the shell's -x (xtrace) option. The latter can be analysed line by line, whereas your screen shot doesn't allow for almost anything...
Second: if you exit anyway after an error has occurred, why not use the shell's -e (exit on non-zero status) and trap builtin?
Where exactly is the script stuck? With all the confusing directory definitions and cd ing, I can't see a file removal in robert_test as "$temp"/"$base" should translate to /mnt/robert_test/temp/testdirtobearchived
sorry its been so long in replying back but sorted it
#!/bin/bash
source=/vol/cha-work/_ARCHIVE/to_be_archived/audio/robert_test
temp=/mnt/robert_test/temp
dest=/vol/cha-archive/audio
echo "is this archive for an audio tar press (t) or an audio directory press (d)"
read option
case $option in
t)
cd "$source"
echo "please specify full path to tar file"
read -e tar
base=$(basename "$tar")
# echo "please enter ID number ie ID1234"
# read id
# echo "please specify where you want the tar file to be stored"
# read -e dest
# echo -e "rename "$base" to "$id"_"$base"\n"
echo -e "move "$base" to "$dest"\n"
echo -e ""$base" will be removed from "$tar"\n"
echo "is this information correct, press (yes) or press (no)"
read correct
case $correct in
yes)
echo "the script will now continue";;
no)
echo "please re-run the script inputting correct details"
exit;;
*)
echo "invalid selection, please re-run the script"
exit;;
esac
# if ! mv "$tar" "$base" ; then
# echo "something went wrong with the move command, please do manually"
# exit
# fi
if ! mv "$base" "$dest" ; then
echo "something went wrong with the move command, please do manually"
exit
fi
# if ! rm -f "$base" ; then
# echo "something went wrong with the rm -f command, please do manually"
# exit
# fi
;;
d)
cd "$source"
echo "please specify full path to directory you want to be made into a tar"
read -e dir
# echo "please enter ID number ie ID1234"
# read id
# echo "please specify where you want the tar file to be stored"
# read -e dest
cd "$dir"
base=$(basename "$dir")
echo -e "COPY "$base" to "$temp"\n"
echo -e "CREATE "$base".tar in "$temp"\n"
echo -e "COPY "$base".tar to "$dest"\n"
echo -e "REMOVE "$base".tar from "$temp" \n"
echo -e "REMOVE "$base" from "$temp"\n"
echo -e "REMOVE "$base" from "$source"/"$dir"\n"
echo "is this information correct, press (yes) or press (no)"
read correct
case $correct in
yes)
echo "the script will now continue";;
no)
echo "please re-run the script inputting correct details"
exit;;
*)
echo "invalid selection, please re-run the script"
exit;;
esac
date >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo "" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
# echo -e ""$id"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e ""$dir"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e "how many files = `find . -type f | wc -l`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
echo -e "size of directory = `du -sh`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
ls -R >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
cd ..
if ! cp -R "$base" "$temp" ; then
echo "something went wrong with the recursive copy command, please do manually"
exit
fi
cd "$temp"
chmod -R 777 "$temp"
if ! tar -cf "$base".tar "$base" ; then
echo "something went wrong creating the tar, please do manually"
exit
fi
if ! cp "$base".tar "$dest" ; then
echo "something went wrong copying the tar, please do manually"
exit
fi
if ! rm -f "$temp"/"$base".tar ; then
echo "something went wrong removing the tar, please do manually"
exit
fi
if ! rm -rf "$temp"/"$base" ; then
echo "something went wrong removing from temp, please do manually"
exit
fi
cd "$source"/"$dir"
cd ..
if ! rm -rf "$base" ; then
echo "something went wrong removing from source, please do manually"
exit
fi;;
*)
echo "invalid selection, please re-run the script"
exit;;
esac