I have a lil' issue while scipting. I have script which will install agents called SCCM and TrendMicro. After I logged in with a sudo priviledge user, I wanna run commands with root user in script. I don't know how to do. I tried sudo for some command which wants root priv. But I get the "sudo: sorry, you must have a tty to run sudo" message. So I want to login with sudo priv. user than change to root and run all the commands.
NOTE:I just add the SCCM installation. After i figured out this, I'll add the TM installation commands in $SCRIPT.
> #!/bin/bash USERNAME=user HOSTS="host1 host2"
SCRIPT="mkdir /tmp/SCCM; wget -O /tmp/SCCM/ccm-Universalx64.tar
> ftp://local/pub/SW/SCCM/ccm-Universalx64.tar; wget -O
> /tmp/SCCM/install ftp://local/pub/SW/SCCM/install; chmod 755
> /tmp/SCCM/*; cd /tmp/SCCM; /tmp/SCCM/install -mp another_host
> -sitecode MGR ccm-Universalx64.tar; /etc/init.d/ccmexecd stop; /etc/init.d/ccmexecd start" for HOSTNAME in ${HOSTS} ; do
> ssh -l ${USERNAME} ${HOSTNAME} "${SCRIPT}"
done exit
Do you have access to the /etc/sudoers
of the host your are connecting to?
This blog and the Unix & Linux Stack Exchange Website point to changing the line in /etc/sudoers
from Defaults requiretty
to Defaults !requiretty
OR to use the -t
or -tt
options to ssh which spawns a pseudo-terminal on the remote side. Beware side effects (see the second above listed link for details).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.