How to write a shell script that runs some commands as superuser and some commands not as superuser, without having to babysit it?

File sutest #!/bin/bash echo “uid is ${UID}” echo “user is ${USER}” echo “username is ${USERNAME}” run it: `./sutest’ gives me uid is 500 user is stephenp username is stephenp but using sudo: sudo ./sutest gives uid is 0 user is root username is stephenp So you retain the original user name in $USERNAME when running …

Read more

Difference between Cron and Crontab?

cron is the general name for the service that runs scheduled actions. crond is the name of the daemon that runs in the background and reads crontab files. A crontab is a file containing jobs in the format minute hour day-of-month month day-of-week command crontabs are normally stored by the system in /var/spool/<username>/crontab. These files …

Read more

How to understand the output of time command?

From: http://zch051383471952.blogspot.com/2010/01/different-of-real-user-sys-time.html Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process. Real is wall clock time – time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if …

Read more

Setting environment variable for one program call in bash using env

It’s because in your first case, your current shell expands the $HELLO variable before running the commands. And there’s no HELLO variable set in your current shell. env HELLO=’Hello World’ echo $HELLO will do this: expand any variables given, in this case $HELLO run env with the 3 arguments ‘HELLO=Hello World’, ‘echo’ and ” (an …

Read more