How can I determine whether a shellscript runs as root or not? [duplicate]

0 0

This question already has an answer here:

How can I determine the sudo password? 5 answers

It's just your regular password.

The password to run commands with sudo is your password, not a separate password. It is the same password that:

you came up with and typed in when you installed Ubuntu or created your account you type in on the login screen (unless you have automatic login) you type in to unlock the screen

When you're asked for your password in a terminal, it is normal that nothing is shown while you are typing it. To enter your password for the sudo command, type it in and press Enter.

If you enter your password correctly and you are an administrator--which on Ubuntu means a user who is allowed to perform actions as the root user through sudo and polkit--then the command will run. (Non-administrators can be permitted to run certain commands with sudo too, but this is not set up by default.)

If you...

0 0

Это ваша лента, где вы будете проводить большую часть времени, получая мгновенные уведомления о том, что интересует именно вас.

Наведите на изображение профиля и нажмите кнопку чтения, чтобы перестать читать любую учетную запись.

Самый быстрый способ поделиться чьим-либо твитом с вашими читателями — ретвитнуть его. Нажмите значок со стрелочками, чтобы мгновенно сделать это.

Поделитесь своими мыслями о любом твите, просто ответив на него. Найдите тему, которая вам интересна, и вступайте в беседу.

Мгновенно узнавайте о том, что обсуждают люди прямо сейчас.

Читайте больше учетных записей, чтобы получать мгновенные обновления о том, что вас больше всего интересует.

Читайте самые последние беседы на любую тему, мгновенно появляющиеся в вашей ленте.

Следите за тем, как разворачиваются лучшие...

0 0



Last Updated March 24, 2016 09:01 AM

How can I determine if a process is running or not and then have a bash script execute some stuff based on that condition...

For example:

if process 'abc' is running, do this

if it is not running , do this.

Answers 9

First thing that came to my mind for your problem:
ps aux | grep -i abc will show the details of the process if its running. You may match the number of lines or time for which its running and compare with zero or any other manipulation. When you run the above command it will show you atleast one line of output i.e. detail about the process created by thi grep command.. So take care of that.
That should do as a simple hack. Put it in the bash script and see if its helpful.

June 29, 2012 22:03 PM

A bash script to do something like that would look something like this:

#!/bin/bash # Check if gedit is running if pgrep "gedit"...
0 0


I tried running a script using nohup like,

nohup &

When I tried

ps -ef | grep ""

I couldn’t find it there except for the grep which is being run with that string as a parameter.

Am I doing it right?. Does this mean that the process has indeed finished execution?


At the beginning of your shell script, write the PID to a file (for example, in /var/run). Then, you can just search for that PID to know if the process is done or not. You can get the PID of your shell script using the built-in $$ variable.

To record the PID, put at the top of your script:

echo $$ > /var/run/

Then, to check if it’s still running:

ps -p `cat /var/run/`

You might not be able to write into /var/run as a normal user. If not, just use /tmp



Subject to nohup implementation, but in most cases it will work.
After running

0 0
LSST v1.05 > Chapter 8 > Examples of Shell Scripts

These exercises are to test your general understanding of the shell scripting. My advise is first try to write this shell script yourself so that you understand how to put the concepts to work in real life scripts. For sample answer to exercise you can refer the shell script file supplied with this tutorial. If you want to become the good programmer then your first habit must be to see the good code/samples of programming language then practice lot and finally implement the your own code (and become the good programmer!!!).

Q.1. How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage
Answer: See Q1 shell Script.

Q.2.Write Script to find out biggest number from given three nos. Nos are supplies as command line argument. Print error if sufficient arguments are not supplied.
Answer: See Q2 shell...

0 0
What You See Is What You Get Element

by Ken Gottry, originally published August 2001

The basics of creating, executing, testing, and launching scripts to control Oracle Solaris with a Korn shell. Includes tips for writing loops.

When programmers start to use Oracle Solaris, they want to begin programming scripts immediately. They're not concerned initially with efficiency and elegance; they're concerned with effectiveness. This article explains my proven shell programming techniques for getting started quickly. As you become more experienced, you can develop your own programming style and improve the efficiency and elegance of your scripts.


The command shell is the layer that interacts with the user and communicates with the operating system. When using MS-DOS, most people use the shell; however a different shell can be specified via the COMSPEC environment variable.

Similarly, each UNIX user must select a command shell to...

0 0