LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-18-2003, 03:40 PM   #1
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Rep: Reputation: 0
Question Shell script running via crontab problem.


Ok, so I'm doing this via my webhost (oktagone). Through Cpanel's UI to crontab. I'm using this script to create a backup of my MySQL database hourly for the times I can't be there to do it myself, I want it time stamped so files are not overwritten (incase the database get's f'ed up, I don't want the backup to be that of a f'ed database).

I'm running this script:

Code:
#!/bin/sh
date=`date -I`
/usr/bin/mysqldump --user=USER --password=PASS --complete-insert --add-drop-table DATABASE | gzip -cf9 > /home/thugg/ibforums$date.gz
Ok, the problem is, the file name contains an illegal char (at least I assume that). I can't delete it, rename it, nothing. I'm going to email them and ask them to do it for me (since they can by inode) I assume that the date variable has a line break character after it, anyone know for sure? I think I may need to add something to remove the illegal char from the date variable, but I'm not sure what the illegal char is, or how to do that. :/

Anyway, if someone could help me rectify this problem, that would be great. I would email them but they'll probably just say "We can have a technician write/correct your script for $30/hour" like they did last time. It's probably a simple fix to those more familier with linux.

Also, the script is being run with the command "/bin/sh /home/thugg/sqlbackup.sh", and I know it's executing (there's about 8 of these backups I can't do s**t with).

Last edited by rshaw; 03-19-2004 at 02:30 PM.
 
Old 12-18-2003, 04:30 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Fist of all, congratulations to your foul language,
we don't see that very often these places.

Secondly, for a diagnosis of the file-name
problem it would help to see the output of
a
ls -l /home/thugg/ibforums*.gz



Cheers,
Tink
 
Old 12-18-2003, 04:51 PM   #3
miaviator278
Member
 
Registered: Dec 2003
Location: Al-Diwania, Iraq (deployed)
Distribution: Slackware ONLY
Posts: 237

Rep: Reputation: 30
man tar
man cpio
and the bash programming how to
and the sh how to
should tell you how to make properly dated backups that u can use.
 
Old 12-18-2003, 05:45 PM   #4
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Tinkster
[B]Fist of all, congratulations to your foul language,
we don't see that very often these places.
Yeah, sorry about that, it's my normal everyday language.

Since I don't have a shell access via telnet or something else, It's not easy for me to do ls, I would have to do it as a cron job that outputs to a file so I can read it. As for the man pages I've read a few. I mainly went off of mysqldump at mysql.com. It's where I originally found the $date thing. I'll read the other ones, though I don't want to tar the output, I just wanted to exactly the same as cpanel does it (and so for the mysqldump command with those options is exactly that, aswell as the gzip). I just wanted it automated and time stamped so It would never overwrite.
 
Old 12-19-2003, 12:26 AM   #5
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Ok, I did the ls (cheaply using crontab, lol). I used the long, all and inode options (-lia). Now I can at least delete via the inode, anyway.

Code:
4088551 -rw-r--r--    1 thugg    thugg      485628 Dec 18 15:20 /home/thugg/ibforums-2003-12-18
.gz
NOTE: The reason for the line break is because the output has the line break char in the file name, so it is infact the line break character. Also I cropped the output to this single line, 'tis all that's needed.

Now I hope all I need is a line to remove the line break from the $date variable, can anyone help me with that? (I've searched quite a bit today, I only found, err 'stuff' for perl and html).
 
Old 12-19-2003, 11:52 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
date=`date -I|tr -d \\012`

Cheers,
Tink
 
Old 12-19-2003, 12:01 PM   #7
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
I will test, but I assume it shall work. I've been messing with tr too, doesn't want to work for me, but I think my syntax was off, and I didn't try it using a pipe.
 
Old 12-19-2003, 12:06 PM   #8
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Well, unfortunatly that did not work. It resaulted in this file:

Code:
4088873 -rw-r--r--    1 thugg    thugg      491859 Dec 19 13:02 ibforums3--9
.gz
With a linebreak after the 9..

Last edited by thetruethugg; 12-19-2003 at 12:07 PM.
 
Old 12-19-2003, 12:16 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Sorry, I had only tried it from a command-line...

Try this
Code:
date="`date -I | tr -d '\\012'`"


Cheers,
Tink
 
Old 12-19-2003, 01:10 PM   #10
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Hmm, well this time the date is there, but the linebreak is still after it, followed by the extension (which I can't see via FTP because the I can't see anything after the line break. I tried replacing the \\012 with \n, but neither worked.

I'm begining to think maybe this is hopeless, but then again I'm by no means optimistic. Or at least that the $30/hour isn't such a rip-off.

Thanks for your help though, and if you have any more ideas, just let me know.
 
Old 12-19-2003, 02:13 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Just out of curiosity: what OS is the site hosted on? ;)


Cheers,
Tink
 
Old 12-19-2003, 02:18 PM   #12
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Red Hat 9.0
 
Old 12-19-2003, 07:23 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Still don't understand WHY it does that, but try
this one:

Code:
#!/bin/sh
file=/home/thugg/ibforums-`date -I`.gz
/usr/bin/mysqldump --user=USER --password=PASS --complete-insert --add-drop-table DATABASE | gzip -cf9 > $file

Cheers,
Tink
 
Old 12-19-2003, 08:56 PM   #14
thetruethugg
LQ Newbie
 
Registered: Aug 2002
Location: lincoln
Distribution: SuSE 8.0 Personal
Posts: 13

Original Poster
Rep: Reputation: 0
Ok, now there's no more return characters or anything wierd like that in the name, but FTP says can't find file (no such file or directory), and cpanel's filemanager says can't stat file, because it doesn't exist. Lol.

ls -lia /home/thugg/* output:

Code:
4088877 -rw-r--r--    1 thugg    thugg      495552 Dec 19 21:43 /home/thugg/ibforums-2003-12-19.gz
I also tried `date +%d%m%y%k%M` incase for some odd reason it was the hyphens, still no luck. File is right there, but it says it can't find it when I try to do anything with it via FTP or cpanel's file manager.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 09:24 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
error running script on crontab haora Linux - Newbie 3 03-11-2005 04:02 PM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
adding a job to crontab via shell script tazio Linux - General 7 10-23-2003 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration