Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a linux script that maintains a log file of each time your VM boots and sh

ID: 3759250 • Letter: W

Question

Write a linux script that maintains a log file of each time your VM boots and shuts down successfully. Create a lab1 directory for this script. The script is an easy one named bootlog.sh that takes a single argument: either "boot" or "shutdown". If the number of arguments is incorrect or if the single argument is neither of the two options then print out an error message like normal. Otherwise, the script should simply print a message into your /home/USERNAME/lab1/boot.log file. The message should contain the current date and time (using the date command), the hostname of the system (using the $HOSTNAME variable), and an indication of if the system booted or shut down.

Note that you should NOT overwrite the log file each time so you'll also need to use the >> I/O redirection operator. Here are some example runs of the script:      
[user@user lab1]$ ./bootlog.sh        
usage:  ./bootlog.sh  boot|shutdown     
[user@user lab1]$ ./bootlog.sh  blah   
  usage: ./bootlog.sh boot|shutdown  
[user@user lab1]$ ./bootlog.sh boot  
[user@user lab1]$  cat boot.log  
Tue Oct  20 12:50:59 EST  2015  
user.user booted!     
[user@user lab1]$ ./bootlog.sh shutdown      
[user@user lab1]$  cat  boot.log  
Tue Oct 20 12:50:59 EST 2015  
user.user booted!  
Tue Oct  20 12:51:05  EST 2015  
user.user shutdown!        
[user@user lab1]$

Note that your script must exit with a status code of zero (the default) if it works correctly (i.e., it was given boot or shutdown as an argument). Any error cases must exit with any non-zero status code.

Explanation / Answer

tux@mercury:~> strace ls

execve("/bin/ls", ["ls"], [/* 52 vars */]) = 0

brk(0) = 0x618000

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)

            = 0x7f9848667000

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)

            = 0x7f9848666000

access("/etc/ld.so.preload", R_OK)      = -1 ENOENT

(No such file or directory)

open("/etc/ld.so.cache", O_RDONLY)      = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=200411, ...}) = 0

mmap(NULL, 200411, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9848635000

close(3)                                = 0

open("/lib64/librt.so.1", O_RDONLY)     = 3

[...]

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)

= 0x7fd780f79000

write(1, "Desktop Documents bin inst-sys ", 31Desktop Documents

bin inst-sys) = 31

close(1) = 0

munmap(0x7fd780f79000, 4096) = 0

close(2) = 0

exit_group(0)     = ?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote