Shell script or scripts which can do some functions
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.
Shell script or scripts which can do some functions
Hi i am not very good in shell scripting, but my goal is to zip or rar files which are made every 25-30 minutes and after that send them to an remote server threw ftp. Adding to that i need that it removes the files which are zipped or rarred older then hour.
What i have edited now is this:
Code:
#!/bin/sh
USERNAME="user"
PASSWORD="password"
SERVER="www.server.com"
# local directory to pickup *.tar.gz file
FILE="/home/coom/test"
# remote server directory to upload backup
BACKUPDIR="/web/testingupload"
# login to remote server
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $BACKUPDIR
lcd $FILE
mput testfile.txt
quit
EOF
it works as its suppose to, to send files to an location on the remote server, but i need to edit it or make a new script which does the requirements i have mentioned above.
The above finds all files in $FILE with a modification time within 35 mins and gzips them.
Just as a side-note, it is possible to use sFTP? Not only is it more secure, it doesn't need you to store the username/password as you can use ssh keys.
-mmin X -> File's data was last modified X minutes ago.
-X -> less then X (-mmin -35 would be 35 minutes or less)
+X -> greater then X (-mmin +60 would be 60 minutes or more)
X -> exactly X (-mmin 15 would be exactly 15 minutes)
The last script in this forum was excellent!
What i wanted to do now is to make a script which removes files older then 7 days threw FTP. I keep having problems coding something because it seems you can't use find in ftp
Could anyone post a shellscript type code which can remove files older then 7 days?
your life will be so much easier if you could use ssh, scp, sshfs, nfs, ... instead of ftp.
however what do the filenames look like on the ftp server ?
if they have date stamps like /var/log/messages-20110807 then you can do something like:
ftp <server>
prompt
mdelete *201107*
The last script in this forum was excellent! What i wanted to do now is to make a script which removes files older then 7 days threw FTP. I keep having problems coding something because it seems you can't use find in ftp. Could anyone post a shellscript type code which can remove files older then 7 days?
Again, read the man page on the "find" command, and use the script you already have. All you have to modify is the find criteria.
Quote:
Originally Posted by Amerika
i can use ssh, but can i automate the script so it works occasionally?
Yes. Put the script into CRON, and have it execute whenever you'd like.
what would i need to write so i could delete any files older then 7 days? The manual is a bit confusing..
No, it really isn't.
Read the man page on the find command....pay attention to the "atime", "ctime", and "mtime" switches. One of them has an EXAMPLE that tells you how to find something two days old. From the man page:
Code:
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed,
any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
Now, if a +1 would be 2 days ago, what do you think would be SEVEN days? You are going to have to put some effort into things, rather than asking people to spoon-feed you answers and write scripts for you. Not meaning to sound nasty, but you could have tested this for yourself, quicker than you could have posted the question here.
It is less confusing when you realise that the find command line is made up of OPTIONS followed by EXPRESSIONS and that EXPRESSIONS are made up of OPTIONS, TESTS, ACTIONS and OPERATORS. With that picture clearly in mind, the layout of the find man page is less confusing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.