LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-10-2011, 05:01 PM   #1
slade
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
need held with bash scripting


hi i was wondering if someone could help me with this assignment of mine, im completely lost.




1.
Create a shell script called usage.bash that requires at least two input arguments. If the script is run with less than two arguments, the script should print out a USAGE statement with a non-zero exit code. Otherwise, it should print out two separate lines stating:

Your first argument was ___ .
Your second argument was ___ .

2.
Create a shell script called newest.bash that takes two filenames as input arguments and prints out the name of the newest file (i.e. the file with the newest last modified date). If two arguments are not passed, display a Usage statement and exit with a non zero status.

3.
Create a shell script called bigger.bash that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's (argument 2) size is BIGGER, SMALLER, or EQUAL to the number (argument 1) provided. If two arguments are not passed, display a Usage statement and exit with a non zero status.


4.
Create a shell script called permissions.bash that takes a filename as an input argument and determines if the file is a normal file, or directory, then prints out the permissions of the file in one of the following forms:


You have read and execute permissions to the directory /etc.

You have read and write permissions to the file ~/.bashrc.

You have read and write and execute permissions to the file permissions.bash.

If one argument is not passed, display a Usage statement and exit with a non zero status.

5.
Create a shell script called fivesecs.bash that starts the command /labs/bash/count.sh and lets it run for 5 seconds, then terminates it. Note, you will need to background the task and then use the kill command. If any arguments are passed, display a Usage statement and exit with a non zero status.
 
Old 11-10-2011, 05:32 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,675

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by slade View Post
hi i was wondering if someone could help me with this assignment of mine, im completely lost.

1. Create a shell script called usage.bash that requires at least two input arguments. If the script is run with less than two arguments, the script should print out a USAGE statement with a non-zero exit code. Otherwise, it should print out two separate lines stating:

Your first argument was ___ .
Your second argument was ___ .

2. Create a shell script called newest.bash that takes two filenames as input arguments and prints out the name of the newest file (i.e. the file with the newest last modified date). If two arguments are not passed, display a Usage statement and exit with a non zero status.

3. Create a shell script called bigger.bash that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's (argument 2) size is BIGGER, SMALLER, or EQUAL to the number (argument 1) provided. If two arguments are not passed, display a Usage statement and exit with a non zero status.

4. Create a shell script called permissions.bash that takes a filename as an input argument and determines if the file is a normal file, or directory, then prints out the permissions of the file in one of the following forms:

You have read and execute permissions to the directory /etc.
You have read and write permissions to the file ~/.bashrc.
You have read and write and execute permissions to the file permissions.bash.
If one argument is not passed, display a Usage statement and exit with a non zero status.

5. Create a shell script called fivesecs.bash that starts the command /labs/bash/count.sh and lets it run for 5 seconds, then terminates it. Note, you will need to background the task and then use the kill command. If any arguments are passed, display a Usage statement and exit with a non zero status.
Sorry, we are not going to do your homework for you. We will HELP you...that means, you post what you've written, and explain where you're stuck. Otherwise, there are thousands of scripting tutorials you can find on Google that can help you:
http://tldp.org/LDP/abs/html/

Posting a homework question verbatim, without doing any of the work is plain lazy and pointless. YOU are taking the class...if you don't learn, what's the point? If you're genuinely having problems, tell your teacher, and they'll work with you, and we're here to help too. But you have to show some effort.
 
1 members found this post helpful.
Old 11-10-2011, 06:09 PM   #3
slade
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
#!/bin/bash

# usage statement
# by student name
# created on 11/10/2011

if [ $# -lt 2 ]
then
echo "USAGE: $0 argument"

this is where im at so far
 
Old 11-10-2011, 06:14 PM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Welcome to LQ!

slade the LQR states;
Quote:
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
TB0ne statements are valid and I for one would be glad to aid you if and when you show some effort or attempt to do the work.

Along with your text and these links you will find helpful information therefore the means to aid you too hopefully answer the query;

Bash Beginners Guide
Bash Reference Manual
Advanced Bash-Scripting Guide


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

Last edited by onebuck; 11-11-2011 at 08:22 AM. Reason: typo-my big digits :)
 
Old 11-11-2011, 07:35 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
http://linuxcommand.org/writing_shell_scripts.php

http://mywiki.wooledge.org/BashPitfalls
 
Old 11-11-2011, 08:08 AM   #6
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
You might find the "stat" command useful for the next part.
 
Old 11-11-2011, 08:34 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,675

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by slade View Post
#!/bin/bash

# usage statement
# by student name
# created on 11/10/2011

if [ $# -lt 2 ]
then
echo "USAGE: $0 argument"

this is where im at so far
Ok..why did you stop? You've completed the first step, so now add a second check to output something if you have two arguments. Then you're done with step one.

Think about step 2. Read the man pages on the find command, and pay attention to the -mtime/atime/ctime switches
Think about step 3. Do an "ls -l", and grab the file size from it to compare against the argument given.
Think about step 4. Do an "ls -l"...look at the string output, which will tell you what it is, and you can parse the permissions from there.
Think about step 5. Read the man page on the sleep command.

Doesn't look like you're stuck, it looks like you stopped trying.
 
Old 11-11-2011, 09:21 AM   #8
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
Sorry to disagree with a Guru TB0ne but I still think that the stat command will be more useful for part 2 that the find command. The time switches on the find command are to search for files when you know something about their times. In the exercise, he is gives the filenames as arguments and needs to extract the time details. He might need to use find to get the full path to the files though.
 
1 members found this post helpful.
Old 11-11-2011, 12:10 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,675

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by trappa01 View Post
Sorry to disagree with a Guru TB0ne but I still think that the stat command will be more useful for part 2 that the find command. The time switches on the find command are to search for files when you know something about their times. In the exercise, he is gives the filenames as arguments and needs to extract the time details. He might need to use find to get the full path to the files though.
No apologies necessary, trappa01. There's always more than one way to do things...I was just trying to give the OP a nudge.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] need help with bash scripting asidrain Linux - Newbie 4 09-05-2010 01:45 PM
BASH Scripting asad_raza5 Programming 7 01-01-2010 01:29 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
Bash scripting vinoth.ilango Solaris / OpenSolaris 6 10-29-2004 04:41 AM
Bash scripting kbeaver Programming 5 07-18-2003 08:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:56 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