Scripting questions

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Scripting questions
# 1  
Old 08-31-2011
Power Scripting questions

I have two scripts and wish to finish the labs in two days, I am not sure how to make these work though. Any help would be appreciated, a step by step guide would be great!

Q1)

Complete the following instructions and submit the questions and answers from this lab to your tutor. Please include the OS you used for this lab with your answer file.
Write a script that meets the following specifications:
  • States the name of the script and time of execution
  • Lists the script to the screen.
  • Gives the hostname
  • Gives the login name, UID, and "real name" of the user running the script
  • States how many arguments were given
  • For each argument, tests if the argument is a regular file, and if so, lists the file in long format (ls -l). If it's not a file, states that the argument either is not a regular file, or doesn't exist
  • Write a small C program that only runs this script. Hint: the C program uses a certain system function call, also called system call. Submit details of creating, compiling, linking and running this program.

Sample output from two different invocations:
Code:
% ./labscript
This is ./labscript, running at Wed Feb 23 20:34:45 PST 2000
It is running on pppl143.moscow.com
Script being run by
 User class
 UID 501
 who is really Cpts 302,Sloan 46,555-1212,555-1212

Called with 0 arguments
% ./labscript arg1 /etc/passwd /dev/null
This is ./labscript, running at Wed Feb 23 20:35:21 PST 2000
It is running on pppl143.moscow.com
Script being run by
 User class
 UID 501
 who is really Cpts 302,Sloan 46,555-1212,555-1212

Called with 3 arguments
-> Argument arg1 either is not a regular file, or doesn't exist
-> Argument /etc/passwd is a file
-rw-r--r-- 1 root root 886 Feb 8 19:29 /etc/passwd
-> Argument /dev/null either is not a regular file, or doesn't exist

In my version of the script, I used echo, date, hostname, grep, cut, a for loop, if-then-else, test, and ls
Read the man pages and experiment to figure out how to do this. One hint -- the following will put the GID into a variable called 'gid'
Code:
gid=`grep "^$USER:" /etc/passwd | cut -d: -f4`

  1. Submit your script
  2. Submit a sample output from your script


Q2)

Complete the following instructions and submit the questions with answers from this lab to your tutor. Please include the OS you used for this lab with your answer file.
Create the following script as /tmp/lab6.sh.
Code:
 #!/bin/sh

 OUTFILE="/tmp/lab6.$$"

 # This command redirects stdout to the file 
 exec >$OUTFILE

 # These are back quotes around "date" in the line below
 echo "running at `date`"

 echo -n "My parent is PID $PPID, "
 # use echo "My parent is PID $PPID, \c" on a System V system

 ps ax | grep $PPID | grep -v grep | cut -c 27-
 # You'll need to modify the above line if you're on a system
 # with an AT&T ps. You may also need to change the column in
 # the cut command if you're using anything but Redhat 6.0

 echo "=============="
 echo "My environment"
 echo "=============="

env Run /tmp/lab6.sh from the command line, and take a look at the output. Now run /tmp/lab6.sh using the at command.
  1. Show the complete command used. How does the output of the at version differ from the output of the command line version? (Hint: the diff command might be useful to you.) -- 2pts Run the command from cron, as user root.
  2. Show the complete procedure used. How does the output differ from the command line output? -- 2pts Run the command from cron, as another user (either one from the previous lab, or one you create for this purpose).
  3. How does this output differ from the output when run as root from cron? -- 2pts Try to set up a crontab that contains errors.
  4. What error did you put into the crontab, and what happened? -- 2pts See if you can submit an at job to run in the year 2029
  5. What happened? Why? -- 2pts Clean up after yourself. Use at -l to get the name of your at jobs, and use atrm to remove the job. Edit your crontab files to remove your entries.
Please guide me thru these two cz I have no idea how to even begin!!!

Last edited by zaxxon; 08-31-2011 at 07:28 AM.. Reason: novel-like subject
# 2  
Old 08-31-2011
Please read the special homework rules and the forum rules (especially rule 11) again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting questions, remote access

Hi, Background: There are 2 servers server1 and server2 In server1 i have my script to perform a functionality from the script in server1 i m calling a script named action in server2. The script action has to check the size of a file in a particular location in server1, if the size of the file... (1 Reply)
Discussion started by: jayii
1 Replies

2. Shell Programming and Scripting

beginner scripting questions User variables

If there's anywhere to look this up, it would be just as helpful. I googled and really couldn't find anything relative to this. ok... General Variables 1) When creating a script I made a file "prog1.sh" does it matter if the end is .sh or is this what has to be done like prog.bash or... (4 Replies)
Discussion started by: austing5
4 Replies

3. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

4. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

5. Shell Programming and Scripting

Shell scripting questions

I have a file like this. Pls help me to solve this. 08-24-2010 10:22:34,xxxxxxxxMessage : 111 08-24-2010 10:24:38,xxxxxxxbMessage : 000 08-24-2010 11:28:11,xxxxxxxcMessage : 111 08-24-2010 11:32:35,xxxxxxxdMessage : 111 08-24-2010 11:32:35,xxxxxxxeMessage : 111 (I should look for Message... (1 Reply)
Discussion started by: mnjx
1 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

Shell/commands/scripting/c questions

1. Can anyone explain me what the line x=signal(SIGINT,nh); does? 2. How do I write a command to print the longest line in a file? 3. How do I write a command to print the last word of every line of a file using sed? 4. What exactly does this line do? :%s/^\(\)\(\)/\2\1/g^M... (3 Replies)
Discussion started by: Necrologist
3 Replies

8. Shell Programming and Scripting

few small scripting questions

hello everyone, i have a couple of questions about programming with shell scripts. -My question is, how do you find out how long a sequence of numbers that has just been entered is. for example If i enter 12345 the length here is 5 and 23456789 the length here is eight. I want to be able... (1 Reply)
Discussion started by: bebop1111116
1 Replies

9. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies

10. UNIX for Dummies Questions & Answers

questions on ftp shell scripting

did a search but was not allowed to use 'ftp' because its too short of a word. for some reason, i can't seem to remember anything about ftp shell scripts - would someone please refresh my memory on the syntax and maybe give a short example? thanks for the time. (5 Replies)
Discussion started by: psyjoniz
5 Replies
Login or Register to Ask a Question