LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-15-2011, 02:36 PM   #1
Manda
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Rep: Reputation: Disabled
Scripting help


*Before I get yelled at, yes this is a homework question, but I have searched and searched, my book is NO help, I don't understand what I find online, and I can't ask my teacher right now. I don't want the whole answer, just point me in the right direction please. I really suck at writing scripts and don't understand what I need to do:


2. Read the following scenario and then complete questions 2a -2c following:
As part of your work in the lab scenario for Lab 9.1, you receive several different types of files from your customer. A manager at your customer’s office recently realized that some files were sent to you a while ago that should not have been.
Your boss has asked you to find the files, create a list of them, and then delete them. The files are stored in /custdata/2007/april and are dated September 20, 2008 (this date being a Saturday, you should have received no files that day).
2. a. Write a script to list the files and send the listing to a file named delete.list, then delete the files.
b. Provide the text of your script in your homework document.
c. Test your script, using this touch command to create files with that date:
touch –t 200809200100 <insert file names here, separated by spaces>

I have created the files, but I don't know how to write the script to do what it wants. I know I have to use vim, and #!/bin/bash and made a file called delete.list to list the files to be deleted. But that's as far as I can understand. Please help, this stuff makes my head hurt!
 
Old 08-15-2011, 02:37 PM   #2
Manda
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Sorry if this is the wrong thread, I wasn't sure
 
Old 08-15-2011, 02:44 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Manda View Post
The files are stored in /custdata/2007/april and are dated September 20, 2008 (this date being a Saturday, you should have received no files that day).
One solution would be to use the "stat" command get a file's time, and use bash's built-in regular expression syntax to check if it matches.

Quote:
Originally Posted by Manda View Post
I know I have to use vim
Vim is not necessary, any text editor will work just as well (not that there's anything wrong with Vim).

Quote:
Originally Posted by Manda View Post
made a file called delete.
You don't need to manually create it before running the script.
 
Old 08-15-2011, 07:40 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I think you'll find these useful

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

They'll teach you almost everything you need to know about bash programming
 
Old 08-15-2011, 08:48 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,005

Rep: Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529Reputation: 2529
Use ls -l to list the files in that directory. Pipe the output through grep in order to isolate the files with that date. Pipe the output again through cut in order to isolate the filenames. Write the filenames to the list of files to delete.

cat the file and pipe it through xargs to run rm on the filename listed on each line.

Last edited by dugan; 08-15-2011 at 08:53 PM.
 
Old 08-15-2011, 09:54 PM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,

you can have a look at this thread for some ideas on how to find files by date.

To make a list you might want to have a look at the -fprintf option of 'find'. Also look up the -delete option of 'find'.
 
Old 08-16-2011, 12:50 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
On top of chrism01's list I would also add:

http://mywiki.wooledge.org/TitleIndex

One of the links is - http://mywiki.wooledge.org/ParsingLs - which will actually refute part of dugan's advice as parsing ls can be fraught with danger.

And +1 to crts' advice and I would add that reviewing the man page of find would be great boon for this assignment.
 
Old 08-17-2011, 02:48 PM   #8
Manda
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks everybody!
 
  


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
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
need help in scripting..... raghuvamsi Programming 2 06-27-2008 05:59 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
scripting anjiie Linux - Newbie 1 02-16-2004 09:17 AM


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