Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i'm writing a shell script which backs up data held in a mysql db, and ftp uploads it to a server. this works perfectly so far.
i plan to set this up as a cron job so it runs daily. however, i don't need to keep all the previous files containing exported data - i only need to keep, say, that last week or fortnights worth of files.
also, is there any way of detecting whether the ftp login and upload was successful, so I can output the appropriate message. The ftp code in my script is as follows:
ftp -in << END-OF-SESSION
open server
user username password
bin
hash
prompt
put backup-$date.sql
bye
END-OF-SESSION
I'm no expert, but maybe do something like ls backup-$date.sql just before bye, and then use an if statement to check if ls provides any output. Would be nice for you to share it once you've completed it though
Originally posted by tomj88 ...but maybe do something like ls backup-$date.sql just before bye, and then use an if statement to check if ls provides any output....
problem is that between the END-OF-SESSION labels everything is treated as a ftp input. i can ls to get the output (or nothing if the file hasn't been uploaded) but then i dont know how i would go about checking this, because i am still in the ftp session
OK, but it looks like that mls might work I did have a perl based mysql backup program but that was bloated... If you want I could try and find that but as I said it was bloated, it would backup to tar.gz files, would email you if you wanted to, could ftp, and you could enable/disable all the options if I remember
i'll have a go using mls first see if that works nicely or not.
at the end of the day my code works perfectly, it just lacks some error handling - its only a small script to set up as a cron job so it'll be fine, but if i can get mls working to keep a log of uploaded files that would be handy!
cool, I'm having a look at that perl script, it's very well commented but has a fair few options. If your script works then I would advise using it because if it breaks, you know how to fix it . Hope mls works...
Neither do I and it's broke straight away haha... I got a couple of tutorials bookmarked on shell scripting so I'm gonna have a go at that now see if I can help you some more .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.