Help,
I am running Ubuntu 23.10 Server and trying to write a script to back up my server. As the script runs it should create an archive and then check for the archive's existence. The relevant code is.
ROOTNAME="/mnt/backup/"\`date +"%Y%m%d"\`
SQLNAME=$ROOTNAME"mysql.sql"
mysqldump -h localhost -u root -pabcd123 --skip-tz-utc -A --add-drop-database --databases > "$SQLNAME" 2> /dev/null
if [ -s $SQLNAME ]
then
echo `date "+%H:%M:%S~%d/$n/%Y"` " SQL Dumped successfully" >> "$LOGNAME"
else
echo `date "+%H:%M:%S~%d/$n/%Y"` " ERROR: SQL Dump Not found exiting...." >> "$LOGNAME"
exit 1
fi
The file generated by the mysqldump statement is being successfully created. However, the if [ test ]; then
statement is not working neither the success nor failure branch of the statement is being followed and I am getting no output to my log file. What am I doing wrong?
and<BR>
charachters I just edited out added by you in the question for styling purpose or you have copied them from your script file and they actually exist there? ... And is the path to your log file defined somewhere in the script i.e. the definition of"$LOGNAME"
doesn't appear in your added script snippet. – Raffa Nov 20 '23 at 17:40LOGNAME
(which is an environment variable that should contain the user's login name). It's far more likely that$LOGNAME
isn't expanding to what you expect than that a simple conditional expression should execute neither branch... – steeldriver Nov 20 '23 at 18:21$LOGNAME
– Raffa Nov 20 '23 at 18:24