Results 1 to 6 of 6
Hello,
I have defined command in script to detect Day, but it doesn't properly.
Here is script
Code:
cd /home/username/`date | awk '{print $1}'`;
/usr/bin/mysqldump --user=mysqluser --password=password --databases databasename database ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-25-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 7
Command problem
Hello,
I have defined command in script to detect Day, but it doesn't properly.
Here is script
OutputCode:cd /home/username/`date | awk '{print $1}'`; /usr/bin/mysqldump --user=mysqluser --password=password --databases databasename database > database.sql
PS :: Folder /home/username/Fri is available on the systemCode:root[~]#sh -x sql-backup-daily-new.sh ++ date ++ awk '{print $1}' + cd $'/home/username/Fri\r' : No such file or directoryne 2: cd: /home/username/Fri
Please help why script is taking day as 'Fri\r' instead of 'Fri'
- 04-25-2010 #2
- 04-25-2010 #3
You may want to try `date +%a`
See `man date` for more options
Can't tell an OS by it's GUI
- 04-25-2010 #4Just Joined!
- Join Date
- Apr 2010
- Posts
- 7
Hello,
Thank you for the reply..
Used printf but doesn't worked.The awk print command always ends its output with the output record separator (ORS). By default, this is newline. You have more control over your output if you use printf.
cat sql-backup-daily-new.sh
cd /home/username/`date | awk '{printf $1}'`;
/usr/bin/mysqldump --user=mysqluser --password=password --databases databasename database > database.sql
date +%a is also not worked.You may want to try `date +%a`
See `man date` for more options
cd /home/holidayg/mysqlbackup/`date +%a`
/usr/bin/mysqldump --user=mysqluser --password=password --databases databasename database > database.sql
- 04-25-2010 #5Then what exactly didn't work?
Originally Posted by eric85
When I try:
It worksCode:mkdir ~/test/`date +%a` cd ~/test/`date +%a` # and even further echo haha>hihi cat ~/test/`date +%a`/hihi # it outputs 'haha'

Can you change your code to:
Code:if [ -d /home/holidayg/mysqlbackup/`date +%a` ] ; then /usr/bin/mysqldump \ --user=mysqluser \ --password=password \ --databases databasename database > \ /home/holidayg/mysqlbackup/`date +%a`/database.sql else echo "Target directory /home/holidayg/mysqlbackup/`date +%a` does not exist" fiCan't tell an OS by it's GUI
- 04-25-2010 #6Just Joined!
- Join Date
- Apr 2010
- Posts
- 7
Thank you for your help. it workedif [ -d /home/holidayg/mysqlbackup/`date +%a` ] ; then
/usr/bin/mysqldump \
--user=mysqluser \
--password=password \
--databases databasename database > \
/home/holidayg/mysqlbackup/`date +%a`/database.sql
else
echo "Target directory /home/holidayg/mysqlbackup/`date +%a` does not exist"
fi


Reply With Quote

