Operating System - HP-UX
1745873 Members
4361 Online
108723 Solutions
New Discussion юеВ

how to write su in shell script

 
rajesh73
Super Advisor

how to write su in shell script

i want to check license status in another user login .i have su permission in sudo file.

kindly find the step to find the license status
sudo su - kumar
cd /home/kumar/lic
lmstat lic |more

Question
kindly help how to write this script in my
login
14 REPLIES 14
Shibin_2
Honored Contributor

Re: how to write su in shell script

Simply put all those in a file and give it an execute permission.

vi script
#!/bin/ksh
sudo su - kumar
cd /home/kumar/lic
lmstat lic |more
:wq!

chmod 755 script

Now run it

./script
Regards
Shibin
rajesh73
Super Advisor

Re: how to write su in shell script

after command excuted loged in kumar but license status command not running

find the output
rajesh &./lic
(c)Copyright 1983-2000 Hewlett-Packard Co., All Rights Reserved.
(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California
(c)Copyright 1980, 1984, 1986 Novell, Inc.
(c)Copyright 1986-1992 Sun Microsystems, Inc.
(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology
(c)Copyright 1989-1993 The Open Software Foundation, Inc.
(c)Copyright 1986 Digital Equipment Corp.
(c)Copyright 1990 Motorola, Inc.
(c)Copyright 1990, 1991, 1992 Cornell University
(c)Copyright 1989-1991 The University of Maryland
(c)Copyright 1988 Carnegie Mellon University
(c)Copyright 1991-2000 Mentat Inc.
(c)Copyright 1996 Morning Star Technologies, Inc.

&





Shibin_2
Honored Contributor

Re: how to write su in shell script

Find, where is lmstat command located

you may have to specify the path.

whereis lmstat or find / -name 'lmstat*'

Then add that path to above script and try.
Regards
Shibin
rajesh73
Super Advisor

Re: how to write su in shell script

rajesh &more lic
sudo su - kumar -----1st line
more /home/kumar/lic/lmstat lic |more -----2nd line



tha above mentioned script after 1st line excuted successfully ,but 2nd line not excuted after the put ctrl+d then it shows you cannot able to access the cd /home/kumar/lic/lmstat file.


output

rajesh&./lic
after login session

kumar& (script stuck)
ctrl+d
/home/kumar/lic/lmstat : not found.

rajesh$

Earl_Crowder
Trusted Contributor

Re: how to write su in shell script

sudo su - kumar -c "cd /home/kumar/lic && /path/to/lmstat lic | more"
rajesh73
Super Advisor

Re: how to write su in shell script

after this command it asking the password:

Dennis Handly
Acclaimed Contributor

Re: how to write su in shell script

>after this command it asking the password:

Does it ask for a password for:
sudo su - kumar -c "id"
Jayakrishnan G Naik
Trusted Contributor

Re: how to write su in shell script

Hi Rajesh

You have many unassigned responses.
127 of 315 responses to my questions.
Encourage the valuable Replies with approprtate points.


Thanks & Regards
Jayakrishnan G Naik
rajesh73
Super Advisor

Re: how to write su in shell script

Hi Jayakrishnan G Naik,

Sorry, it will not happen in future.


After this command

output
sudo su - kumar -c "id"
Password:

kindly help to sort out this issue