日期:2014-05-16  浏览次数:20789 次

从root切换到另一个用户执行命令,shell脚本怎么写:
我想在root下敲 sh test.sh,test.sh要执行以下步骤,这个bash脚本怎么写?


我写了一个如下:
#!/bin/bash
# Program:
# This program import the 'ZJIF' user.
# History:
# 2010/07/01 HanLiangYuan First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:$ORACLE_
HOME/bin
cd /etc/samba
mv smb.conf smb.confBAK
touch smb.conf
这里不知道怎么办了。。
su oracle 这句好像也有问题,卡死不动了
sqlplus / as sysdba
select sysdate from dual;
select sysdate from dual;
exit;

想要tesst.sh实现的操作如下:

[root@localhost ~]# cd /etc/samba
[root@localhost samba]# mv smb.conf smb.confBAK
[root@localhost samba]#touch smb.conf
然后把下面这段写入smb.conf中;
[global]
workgroup = LinuxSir
netbios name = LinuxSir05
server string = Linux Samba Server TestServer
security = share

[linuxsir]
  path = /opt/linuxsir
  writeable = yes
  browseable = yes
  guest ok = yes
然后执行
[root@localhost samba]# su oracle 
然后执行
[oracle@localhost samba]$ sqlplus / as sysdba
SQL> select sysdate from dual;
SQL> select sysdate from dual;
SQL> exit;







------解决方案--------------------
su oracle 这句好像也有问题,卡死不动了
sqlplus / as sysdba
select sysdate from dual;
select sysdate from dual;
exit;
改成
C/C++ code

su - oracle <<EOF
sqlplus / as sysdba
select sysdate from dual;
select sysdate from dual;
exit;
EOF

------解决方案--------------------
其实touch smb.conf 这句都是多余的