Monday, December 16, 2013

su in shell script non intractive mode

www.unixbabuforum.inAny scripting experts out there that can point me to the right direction of writng a script to use su given user without any users interaction such as entering passwd

www.unixbabuforum.inYour script must run from root. 

From the second paragraph of su's man page: 

To use su, the appropriate password must be supplied (unless the 
invoker is already root).

www.unixbabuforum.inYou may also use su with I/O redirection. Please see example script bellow where su is use before accessing a sybase db: 
sauid=sa # user variable# 
sapasswd=sybase12 #passw variable# 
date=`date +%Y%m%d` 
LOGIN="isql -U$sauid -P$sapasswd -SPPLE_SYB -w1000" 
su - testuser << AE > sys_mon.${date}.txt 
sp_sysmon "00:01:00", @applmon = appl_and_login 

www.unixbabuforum.inUse sudo, not su. 


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM