There are times that you need to execute a script as another user, usually to make sure you do not mess up the access rights of the files that will be produced after the execution of the script.
An easy way to do it is using the command su (su allows to run commands with a substitute user and group ID).
An example would be to use it as su - <USER> -c "<COMMAND>”
The – <USER> will start the shell as a login shell with an environment similar to a real login.
The -c “<COMMAND>” will pass the command after -c to the newly created shell, you should wrap it in quotes if you want to pass parameters to your command.
When you call a command like this: sudo someCommand and you get an error message saying Cannot Connect to X Server, while if you executed that command without the sudo it would execute properly, you can resolve this issue by replacing "sudo" with "xgd-su -u root -c" resulting the following…
The following methods demonstrate different methods on how to compute the time a potion of code or script take to complete their execution. [download id="2158"] Method 1 - Using date The following example will calculate the execution time in seconds by subtracting the system date and time in seconds…