LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02: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, 04:14 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
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 04:39 PM. Reason: code tags
 
Old 12-19-2010, 04: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, 05:07 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 05:08 AM   #5
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
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, 05:12 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 06:57 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by druuna View Post
EDIT:
Way to slow......
/EDIT
But the most complete explanation
 
Old 08-11-2011, 06: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, 08:05 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ 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, 11:23 AM   #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, 11:38 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,684

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
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 11:40 AM.
 
Old 08-12-2011, 12:25 PM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 12:28 PM.
 
Old 08-13-2011, 05: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, 05:10 PM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,684

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
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 05:14 PM.
 
Old 08-13-2011, 09:31 PM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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



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

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

All times are GMT -5. The time now is 10:31 AM.

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