LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-18-2010, 03:46 PM   #1
Amerika
LQ Newbie
 
Registered: Dec 2010
Posts: 18

Rep: Reputation: 0
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.
 
Old 12-18-2010, 05:14 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

That will be two scripts, I guess, one for the zip & move, one
for deletion. Use cron in conjunctions w/ 'find', e.g.,
Code:
find $FILE -type f -mmin -35 -exec gzip {} \;
and to delete older files
Code:
find $FILE -type f -mmin +60 -exec rm {} \;



Cheers,
Tink

Last edited by Tinkster; 12-18-2010 at 05:39 PM. Reason: code tags
 
Old 12-19-2010, 05:26 AM   #3
Amerika
LQ Newbie
 
Registered: Dec 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Code:
find $FILE -type f -mmin -35 -exec gzip {} \;
-mmin -35 means what exactly?
 
Old 12-19-2010, 06:07 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Amerika View Post
Code:
find $FILE -type f -mmin -35 -exec gzip {} \;
-mmin -35 means what exactly?
From the find man page:
Code:
       -mmin n
              File's data was last modified n minutes ago.
 
Old 12-19-2010, 06:08 AM   #5
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 553

Rep: Reputation: 116Reputation: 116
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.


[edit] ^^ beat to it!
 
Old 12-19-2010, 06:12 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Hi,

-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)

Hope this clears things up.

EDIT:
Way to slow......
/EDIT
 
Old 12-19-2010, 07:57 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by druuna View Post
EDIT:
Way to slow......
/EDIT
But the most complete explanation
 
Old 08-11-2011, 07:40 AM   #8
Amerika
LQ Newbie
 
Registered: Dec 2010
Posts: 18

Original Poster
Rep: Reputation: 0
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?
 
0 members found this post helpful.
Old 08-11-2011, 09:05 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,167

Rep: Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890
^ what type of server are you connecting to ?

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*
 
Old 08-12-2011, 12:23 PM   #10
Amerika
LQ Newbie
 
Registered: Dec 2010
Posts: 18

Original Poster
Rep: Reputation: 0
i can use ssh, but can i automate the script so it works occasionally?
 
0 members found this post helpful.
Old 08-12-2011, 12:38 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,328

Rep: Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471
Quote:
Originally Posted by Amerika
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 View Post
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.

Last edited by TB0ne; 08-12-2011 at 12:40 PM.
 
Old 08-12-2011, 01:25 PM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,167

Rep: Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890
Quote:
Originally Posted by Amerika View Post
i can use ssh, but can i automate the script so it works occasionally?
my advice to you would be to mount the directory on the server using something like sshfs and running the find command from cron.

i.e.- try to use the insecure, deprecated, featureless ftp as least as possible.

Last edited by schneidz; 08-12-2011 at 01:28 PM.
 
Old 08-13-2011, 06:00 PM   #13
Amerika
LQ Newbie
 
Registered: Dec 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
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.

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..
 
Old 08-13-2011, 06:10 PM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,328

Rep: Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471
Quote:
Originally Posted by Amerika View Post
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.

Last edited by TB0ne; 08-13-2011 at 06:14 PM.
 
Old 08-13-2011, 10:31 PM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Amerika View Post
The manual is a bit confusing..
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to Write & Call Functions Within Shell Scripts senthilmuthiah Linux - Newbie 2 03-27-2009 07:36 PM
How to properly exit functions in Shell Script? Jude Terror Programming 5 01-27-2009 04:15 PM
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 07:24 AM
passing parameters to functions in shell script kushalkoolwal Programming 1 09-28-2005 03:40 PM
shell script functions iNET_boss Linux - General 1 08-10-2005 05:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration