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:

% ./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'

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.

 #!/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!!!

Please read the special homework rules and the forum rules (especially rule 11) again.