Shell script ,being root


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script ,being root
# 1  
Old 10-24-2010
Shell script ,being root

It needs be root for some command and not for other commands.
Code:
fdisk -l
ls -l
cd /etc

For fdisk -l need root password.
After fdisk -l i want to be again a normal user.
How can i this with shell script?
# 2  
Old 10-24-2010
if you call su -c "fdisk -l" su will prompt for root password.

If you want to avoid password prompts consider using sudo, or allow ssh to root@localhost for user with non-interactive (public/private keys) authentication.

sudo is good cause you can allow users in particular groups to run specific commands (ie it's quite configurable on who can do what as root (or any other user for that matter) ).
# 3  
Old 10-24-2010
Quote:
Originally Posted by Chubler_XL
if you call su -c "fdisk -l" su will prompt for root password.

If you want to avoid password prompts consider using sudo, or allow ssh to root@localhost for user with non-interactive (public/private keys) authentication.

sudo is good cause you can allow users in particular groups to run specific commands (ie it's quite configurable on who can do what as root (or any other user for that matter) ).
I want to type root password for one time for all admin commands.
After that i want to exit to be normal user.
Then being normal user i will continue with other commands.
Can you post a sample script to do this?
# 4  
Old 10-24-2010
set sudo with NOPASSWD for your own account, with that, when you run fdisk with sudo in your account, it will run as root.

Code:
  (root) NOPASSWD: /usr/sbin/fdisk

So change your script to:

Code:
sudo /usr/sbin/fdisk -l
ls -l
cd /etc

# 5  
Old 10-25-2010
Quote:
Originally Posted by rdcwayx
set sudo with NOPASSWD for your own account, with that, when you run fdisk with sudo in your account, it will run as root.

Code:
  (root) NOPASSWD: /usr/sbin/fdisk

So change your script to:

Code:
sudo /usr/sbin/fdisk -l
ls -l
cd /etc

I want to give password for root.
But i don't want to be root for normal command.
As we do in terminal,typing root password type admin command then doing exit type normal command.

Is there any other way except sudo?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parsing Root password inside a C shell script

Hello everyone, I want to check how long a remote computer is running (e.g. with the command uptime or who - b) The check should be done during login from none root user by a script which is called from .cshrc. My script works fine if I login as root but I want that everybody get the information... (5 Replies)
Discussion started by: Nadielosabra
5 Replies

2. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies

3. Shell Programming and Scripting

Shell script to install and set JAVA_HOME as non root user

HI I am trying to install JAVA and set JAVA_HOME variable in non-root user mode. I am trying to write a script for that. I am doing it by downloading a tar ball.Any inputs will be helpful. (1 Reply)
Discussion started by: sailu_mvn
1 Replies

4. HP-UX

Su to another user from root doesn't work within shell script

Hello I have a shell script that is run as root. Script rins ok until the point where it have to switch to user "mqm" to run other commands. It just hangs at the point of this line in the script su - mqm -c "dspmq" I ran the same commands at the terminal and they run fine. Any thoughts. (6 Replies)
Discussion started by: mo12
6 Replies

5. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

6. Shell Programming and Scripting

Shell script for to view all users & groups history in root

Dear All, I want to know all users & group history in one file, for root terminal through shell or any other option (5 Replies)
Discussion started by: kpoobathi
5 Replies

7. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. Shell Programming and Scripting

Shell script to find when user su'ed to root

Does anybody know how to make a shell script that finds all the times that any user su'ed to root and create a cron job sends that file output via e-mail to one user? Thanks!:confused: (1 Reply)
Discussion started by: jrvilino
1 Replies

9. AIX

Can't login root account due to can't find root shell

Hi, yesterday, I changed root's shell in /etc/passwd, cause a mistake then I can not log in root account (can't find correct shell). I attempted to log in single-mode, however, it prompted for single-mode's password then I type root's password but still can not log in. I'm using AIX 5L version 5.2... (2 Replies)
Discussion started by: neikel
2 Replies

10. UNIX for Dummies Questions & Answers

Run non-root script as root with non-root environment

All, I want to run a non-root script as the root user with non-root environment variables with crontab. The non-root user would have environment variables for database access such as Oracle or Sybase. The root user does not have the Oracle or Sybase enviroment variables. I thought you could do... (2 Replies)
Discussion started by: bubba112557
2 Replies
Login or Register to Ask a Question