LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2012, 05:00 AM   #1
suboss87
Member
 
Registered: Dec 2010
Posts: 31

Rep: Reputation: 0
Question need a help for shell script


Hi,
Hereby i do attached the script which should be run only by root, yet root login was disabled in server. So within the script i need to switch to root account and the script should be executed. Please help me to resolve this. I am trying to run the script but the script fails in first step after switching to root account.


#!/bin/bash

su -
echo "password"


usr1=gprsuser
usr2=prov
pass1=gp123#
pass2=pr123#
#group=groupname

/bin/mkdir -p /102/gprsuser
/bin/mkdir -p /102/prov/PROV_LIS_RESP_DIR
/bin/touch /script_log
#/usr/sbin/groupadd groupname -g 501

/usr/sbin/useradd -d /102/gprsuser -m -s /sbin/nologin -g 500 -u 520 $usr1
passwd $usr1 << EOF
$pass1
$pass1
EOF
#cp /etc/skel/. /102/$usr1
#chown -R $usr1:$group /102/$usr1
chmod -R 770 /102/gprsuser
grep gp /etc/passwd
if [ $? -eq 0 ]
then
echo "gprsuser created sucessfully on `date`" >> /script_log
else
echo "gprsuser failed to create on `date`" >> /script_log
fi
 
Old 07-30-2012, 05:19 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
you can't su in the middle of a script, it makes no sense as it create s a shell there, it won't just carry on. Remove the su - line, and run the script through a framework like sudo.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 01:45 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM


All times are GMT -5. The time now is 12:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration