Thank you very much for viewing my post and offering your suggestions & help. I really appreciate it. ~Simba
1. The problem statement, all variables and given/known data:
File "Ageing" Shell Script
Part A) Write a shell script that will count the number of files in your account that were last modified 5 or more days ago. When you run the shell script, the results should look something like this:
%ageing
There are 19 files modified 5 or more days ago.
%
Part B) Modify your script (or re-write it if you wish) to allow the user to choose what the script should use for the last modified day. Example:
%ageing 15
There are 4 files modified 15 or more days ago.
Part C) Modify the script to get it to count back up to "X" number of days and list the files that were modified for each day. Example:
%ageing -3
Files modified 1 day ago
./a.txt
./b.txt
Files modified 2 days ago
./2days.txt
./dir1/test _file.txt
./dir2/test _file2.txt
Files modified 3 days ago
(none)
Note: (you may have to test the results environment variable to
get this to work)
Ageing should still work like it did in Part B if you type this command (note, it is still 3 or more days):
%ageing 3
The number of files modified 3 or more days ago is 4.
2. Relevant commands, code, scripts, algorithms:
I have determined that it is best to use the "Find" command (as a basis) to solve this problem. The script can be written in either bash, bourne shell, or csh, but bourne or bash is best if possible.
3. The attempts at a solution (include all code and scripts):
So far all I have determined is to use the find command. I am new to unix.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Boston University, Boston, MA, Prof McBee, Unix2201
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
While this will surely work as desired wouldn't it be easier to include the test in the loop already?
@Simba-DMB
You might want to read this post for a little introduction on how to use find. Try a few find commands to see the various effects. Once you understand how to use find read the man page of it (issue man find at the command line) to get more clauses to use.
@bakunin: Sure it'd be easier and less typing. Simba-DMB claims to be new to unix and I didn't want to burden him already with things that are not-so-obvious to a newbie :-)
In my humble opinion,
is more easily understood than
In my humble opinion,
[...]
is more easily understood than
hmm.. I came to systems administration via programming and the concept of loop-until/while-some-condition was natural for me. This construct exists in every programming language i know (well, with the exception of APL2 ;-) ).
Still, you might be right. People without a programming background understand your version more easily maybe.
@SimbaDMB: you see, most things you do in Unix can be achieved in a number of different ways. Unix is - you will learn to love this - not only about achieving a certain goal, but doing so in (a certain) style. [philosophical mode on]In fact Unix is as much a culture - a way of life, even - as it is an operating system.[/philosophical mode off].
@bakunin: Sure it'd be easier and less typing. Simba-DMB claims to be new to unix and I didn't want to burden him already with things that are not-so-obvious to a newbie :-)
In my humble opinion,
is more easily understood than
I disagree. The 'true' makes no sense unless you understand you could put a condition there -- and if you could put a condition there, why not do so?
First, thanks balajesuri and bakunin. Your posts were a big help!
What I am posting below encompasses parts A, B and C. I still need a little help with part A.
------------------------------------------------------------------------------- Part A.
The script is called without an argument. It calls the function PastXDays with an argument of 5, giving you the files that were modified in the past 5 days. This is the only part I have incomplete as I need this to be a count rather than a list of files (e.g. the output should be something like this "There are 19 files modified 5 or more days ago.")
If you can offer suggestions to figure this out, I would much appreciate it.
Part B:
The script is called with a positive integer
It calls the PastXDays function with the positive integer, giving you an output like this:
These are the files modified within the past 3 days:
.
./-1]
./.DS_Store
./525AF2D3F89B4FE6D814B61372989F68B7C94795.torrent
./=
./=0]
./find.txt
./Pilot Guides (Lonely planet)-Nepal.DC.DIVX.avi
./UnixPartA.sh
./UnixPartB.sh
./UnixPartC.sh
Part C:
The script is called with a negative integer.
I create a variable to reverse the sign of the negative argument. I then run through a loop which runs the function, then decreases the count, and the loop is ran until the count reaches 0.
Hi All,
I have the below code(.sh) and need to send an email.
#!/bin/bash
cp /u02/xxc_incoming/TEST*.dat /u02/xxc_archive_incoming/AMER7764_ARPP_2/
cat /u02/xxc_incoming/TEST*.dat > /u02/xxc_incoming/XXC_TEST.dat
rm /u02/xxc_incoming/TEST*.dat
cd $XXC_TOP/bin
sqlldr userid=apps/<pwd> ... (12 Replies)
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi,
This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
Hi
I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message
No utpmx entry: you must exec "login" from lowest level "shell" :confused:
What i want is: open various... (0 Replies)