In your account on both the class Linux machine and your personal Linux machine:
ID: 3834992 • Letter: I
Question
In your account on both the class Linux machine and your personal Linux machine:
Make sure that ~/etc directories exist for yourself. If not, create them. Make a backup of your ~/.bashrc file, for instance, copying it to a file called ~/.bashrc.BAK. Add each ~/etc directory, in their respective .bashrc files, to the PATH variable. Make sure the PATH variable is properly updated and everything still runs correctly when you login after this update has been made.
a. TROUBLESHOOTING TIP: In order to avoid problems while testing to make sure everything runs correctly for new logins, you may wish to 1) remain logged into one putty session, while you 2) login to a second putty session to check that everything works correctly:
b. A successful test will show: You can issue Linux commands correctly, you can echo the contents of the PATH variable and see that it is correct, you can run scripts in the ~/etc directory, that no “strange” messages or errors show up on the command-line, etc. If so, you are good to proceed.
c. If your test is unsuccessful: Do not log out of your first putty connection! Rather, log out of the second putty connection, go back to your first putty connection and re-edit the .bashrc file and re-test as described above to make sure that the new configuration follows correct syntax and gets the desired directory added to the PATH variable correctly.
d. If your PATH update is still unsuccessful: repeat this process until you have everything working correctly, being sure to always have one open connection to your machine at any given time. In the worst case, restore your backup .bashrc file and seek help. You can do the remaining parts of the assignment without having gotten the PATH updated to include your ~/etc directory.
4. (2 pts) cron Part 1 – On your personal Linux machine, enter the following command in your individual crontab (crontab -e) and verify that it generates proper output in the proper location every minute: * * * * * echo "$(whoami): $(date): Hello (Part 1)" >> ~/etc/cron_output.data 5.
(2 pts) cron Part 2 – On your personal Linux machine, comment out the individual crontab command that you created above and create a script called ~/etc/cron_hello_part2 with the command used in Part 1 in it and call it from your individual crontab. An example individual crontab command and an example script to do this are listed below:
* * * * * ~/etc/cron_hello_part2 ~/etc/cron_hello_part2 script example: #!/bin/bash echo "$(whoami): $(date): Hello (Part 2)" >> ~/etc/cron_output.data
6. (2 pts) cron Part 3 – On your personal Linux machine, comment out the cron entries in your individual crontabs (so they don’t keep running and potentially over-fill your filesystem!). Leave the output file showing the entries that have been generated as you set up and tested your crontab entries. (Note: If we were to go back and uncomment all the cron entries in the individual system crontabs then all of these should run simultaneously. You should consider testing to make sure this is so before commenting them all out.)
Explanation / Answer
Question)
Make sure that ~/etc directories exist for yourself. If not, create them.
Make a backup of your ~/.bashrc file, for instance, copying it to a file called ~/.bashrc.BAK.
Add each ~/etc directory, in their respective .bashrc files, to the PATH variable.
Make sure the PATH variable is properly updated and everything still runs correctly when you login after this update has been made.
Ans)
> ls -lthr ~/etc
> mkdir ~/etc # Creating etc directory if it does not exist
> cp ~/.bashrc ~/.bashrc.BAK # making a backup copy of .bashrc file
> vi ~/.bashrc
> PATH=$PATH:~/etc # To add etc directory in the PATH variable of .bashrc file
> echo $PATH # To check if path variable has the new value updated
Question)
a. TROUBLESHOOTING TIP: In order to avoid problems while testing to make sure everything runs correctly for new logins, you may wish to
1) remain logged into one putty session, while you
2) login to a second putty session to check that everything works correctly:
b. A successful test will show: You can issue Linux commands correctly, you can echo the contents of the PATH variable and see that it is correct, you can run scripts in the ~/etc directory, that no “strange” messages or errors show up on the command-line, etc. If so, you are good to proceed.
Ans)
> echo $PATH # to check if path variable is updated with ~/etc directory
> source ~/.bashrc # once .bashrc is updated, run thiscommand so the new changes reflected in current shell
Now you should be able to execute commands in ~/etc unless you dont have permissions to execute
c. If your test is unsuccessful: Do not log out of your first putty connection! Rather, log out of the second putty connection, go back to your first putty connection and re-edit the .bashrc file and re-test as described above to make sure that the new configuration follows correct syntax and gets the desired directory added to the PATH variable correctly.
d. If your PATH update is still unsuccessful: repeat this process until you have everything working correctly, being sure to always have one open connection to your machine at any given time. In the worst case, restore your backup .bashrc file and seek help. You can do the remaining parts of the assignment without having gotten the PATH updated to include your ~/etc directory.
Question)
4. (2 pts)
cron Part 1 – On your personal Linux machine, enter the following command in your individual crontab (crontab -e) and verify that it generates proper output in the proper location every minute: * * * * * echo "$(whoami): $(date): Hello (Part 1)" >> ~/etc/cron_output.data 5.
Ans)
To put command in the crontab:
> crontab -e
then type the following command in the editor:
* * * * * echo "$(whoami): $(date): Hello (Part 1)" >> ~/etc/cron_output.data
Type below command to see if your cron entry is added properly:
> crontab -l
If the above crontab commands run without issues then you should see ~/etc/cron_output.data updated every minute
Verify ~/etc/cron_output.data file using below command:
> cat ~/etc/cron_output.data
Question)
5. (2 pts) cron Part 2 – On your personal Linux machine, comment out the individual crontab command that you created above and create a script called ~/etc/cron_hello_part2 with the command used in Part 1 in it and call it from your individual crontab. An example individual crontab command and an example script to do this are listed below:
* * * * * ~/etc/cron_hello_part2 ~/etc/cron_hello_part2 script example: #!/bin/bash echo "$(whoami): $(date): Hello (Part 2)" >> ~/etc/cron_output.data
Ans)
create a file with name ~/etc/cron_hello_part2:
> vi ~/etc/cron_hello_part2
type the below entries in editor and save
#!/bin/bash
echo "$(whoami): $(date): Hello (Part 2)" >> ~/etc/cron_output.data
Now comment the previous crontab entry and add the above script in crontab:
> crontab -e
then type the following command in the editor:
#* * * * * echo "$(whoami): $(date): Hello (Part 1)" >> ~/etc/cron_output.data
* * * * * ~/etc/cron_hello_part2
To list the crontab entries and see if your changes have gone properly:
> crontab -l
Question)
6. (2 pts) cron Part 3 – On your personal Linux machine, comment out the cron entries in your individual crontabs (so they don’t keep running and potentially over-fill your filesystem!). Leave the output file showing the entries that have been generated as you set up and tested your crontab entries. (Note: If we were to go back and uncomment all the cron entries in the individual system crontabs then all of these should run simultaneously. You should consider testing to make sure this is so before commenting them all out.)
Ans)
To not overfill your system, commenting out the crontab entries
> crontab -e
then comment the entries in crontab editor:
#* * * * * echo "$(whoami): $(date): Hello (Part 1)" >> ~/etc/cron_output.data
#* * * * * ~/etc/cron_hello_part2
To list the crontab entries and see if your changes have gone properly:
> crontab -l