Help on a fairly complicated shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on a fairly complicated shell script
# 8  
Old 05-09-2017
I will try it tonight at home (now I am already in the office, Italy) and I will let you know.

In the meanwhile thank you so much.

---------- Post updated at 01:11 PM ---------- Previous update was at 02:13 AM ----------

Quote:
Originally Posted by RudiC
Do I read that orrectly that the oldest files' sizes should sum up to $GG, and, when below, be deleted? Try (shamelessky stolen from Chubler_XL):

Code:
find . -type f -mmin +$MM -printf "%T@ %s %h/%f\\n" | sort -n | awk -vMXSZ=$GG '
(TOTSZ+=$2) < MXSZ      {print "rm -i", $3
                         next
                        }
                        {exit
                        }

If happy with the result, pipe it through sh!
Hello,
I am testing the script.

In my current version, I delete all files oder than $MM.
Now I need to start the deletion from the oldest file in the path/directory and the deletion should stop either when I delete $MM minutes of files in total or $GG mb of files in total (starting from the oldest one) whatever is easier to implement.

Can you please check it? I apologize if I have not been very clear.

Thanks,
daniele


Thanks for helping,
daniele

Last edited by dcaccount; 05-09-2017 at 03:31 PM..
# 9  
Old 05-09-2017
The closing ' is missing, at the end of the embedded awk script.
I wonder if you can simply do
Code:
find . -type f -mmin +$MM -printf "%T@ %s %h/%f\\n" |
 sort -n | 
 awk -vMXSZ=$GG '(TOTSZ+=$2) >= MXSZ { exit } { print "rm -i", $3 }'


Last edited by MadeInGermany; 05-09-2017 at 03:44 PM.. Reason: A fix
These 2 Users Gave Thanks to MadeInGermany For This Post:
# 10  
Old 05-10-2017
Quote:
Originally Posted by RudiC
Do I read that orrectly that the oldest files' sizes should sum up to $GG, and, when below, be deleted? Try (shamelessky stolen from Chubler_XL):

Code:
find . -type f -mmin +$MM -printf "%T@ %s %h/%f\\n" | sort -n | awk -vMXSZ=$GG '
(TOTSZ+=$2) < MXSZ      {print "rm -i", $3
                         next
                        }
                        {exit
                        }

If happy with the result, pipe it through sh!
It works!
How can I "pipe through sh"? Shall I replace print with sh?

Thanks,
daniele
# 11  
Old 05-10-2017
Code:
.....
{exit}' | sh

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assistance on complicated perl script

As a followup to my previous thread, I'm trying to make a complicated perl script that involves storing information from a text file into a hash, and giving the user the ability to change the information present/write the information currently inside the hash to a new file. This is the code I've... (8 Replies)
Discussion started by: Eric1
8 Replies

2. Solaris

Solaris? Is it really this complicated?

Hello Everybody, I am a mid-level Linux administrator trying to get a hold of Solaris. So far, my experience has been painful. I think it's confusing and it's just a big mess... To be more specific, I have noticed that whenever I install a package... it never followed a specific pattern.... (4 Replies)
Discussion started by: EssenceNY
4 Replies

3. Shell Programming and Scripting

Script Search replace - complicated

I have a text file for which i need a script which does some fancy search and replace. Basically i want to loop through each line, if i find an occurance of certain string format then i want to carry on search on replace another line, once i replaced this line i will contine to search for the... (7 Replies)
Discussion started by: kelseyh
7 Replies

4. Programming

Read/Write a fairly large amount of data to a file as fast as possible

Hi, I'm trying to figure out the best solution to the following problem, and I'm not yet that much experienced like you. :-) Basically I have to read a fairly large file, composed of "messages" , in order to display all of them through an user interface (made with QT). The messages that... (3 Replies)
Discussion started by: emitrax
3 Replies

5. Programming

Does realloc free fairly?

Hello, my program works properly but valgrind tells me I am not freeing allocated memory. I think the problem is in realloc. I am pretty sure I do something wrong with realloc, because I changed it a bit and valgrind noticed less errors (that the program wasn't working properly with less errors... (3 Replies)
Discussion started by: samciz
3 Replies

6. Shell Programming and Scripting

need help with script - output to file, but complicated

ok, so what i want to do is make a script that will do the following: take out from a command in the terminal put that output into a text file already on my computer. the only thing is that i need to put the output in the file kinda weird: i need to take it and put each character of output... (13 Replies)
Discussion started by: twoodcc
13 Replies

7. UNIX for Dummies Questions & Answers

complicated(?) grep

Hi all, I need help to figure out this grep. I would like to search all files in a directory for the occurrence of abc AND xyz. I started with this: grep -i abc * | grep xyz But this only returns lines which contain both values on the same line. So I am thinking that I need to do... (5 Replies)
Discussion started by: khearnen
5 Replies

8. UNIX for Dummies Questions & Answers

Fairly new to scripting

Hi, my team has existing ftp scripts that basically ftp files from one server to the other. Can anyone show me how to add some lines where if the ftp fails, an email could be sent out to myself and others on my team so that we are alerted? Thanks in advance. (11 Replies)
Discussion started by: ocanyc
11 Replies

9. Shell Programming and Scripting

Very complicated script..

I have a script that I need to create tha involves moving files and renaming them(see previous post) Are there any websites with user made shell scripts? (5 Replies)
Discussion started by: rocinante
5 Replies

10. Shell Programming and Scripting

Need help with complicated script (reading directories, extracting data)

Hi, people. I was searching script tutorials/examples and found this forum, and thought to ask for help, because there seems to be many wise people here. (Try to bare with me, I'm a Windows user, so this stuff is somewhat strange to me, OK? :rolleyes: ) Anyways, I need to create a script that... (3 Replies)
Discussion started by: Gill Bates
3 Replies
Login or Register to Ask a Question