-3

I recently attempted to run a boot up script which failed I didn't know why it failed so I posted a question about that here.

chkconfig bootup script failing, script runs good manually

Where the user schaiba suggested I add >> /tmp/test.log 2>&1 at the end of my start up script to log and figure why it doesn't start.

I realized that it has the following problem.

sudo: sorry, you must have a tty to run sudo failed

I looked in my script and found this line, pretty much the important line that starts up my java program. (which is the $cmd)

javaCommand="java"                                         # name of the Java launcher without the path
javaArgs="-classpath .:recaptcha4j-0.0.8.jar:mysql-connector-java-3.0.17-ga-bin.jar ChatServer"                     # arguments for Java launcher
javaCommandLine="$javaCommand $javaArgs"                       # command line to start the Java service application

cmd="nohup $javaCommandLine >>$serviceLogFile 2>&1 & echo \$! >$pidFile"

   # Don't forget to add -H so the HOME environment variable will be set correctly.
   sudo -u $serviceUser -H $SHELL -c "$cmd" || return 1

When looking what to do with that error about sudo failing.. Lots of solutions state I should disable the Defaults require-tty in etc/sudoers which another article wrote would give me a security vulnerability where SSH users could see my root password, even though SSH already logs in root haha, anyways I don't want to disable any security.

My guess is I need to add that -H to some Home environment variable which I have no idea what that means anyone know what I have to do there?

Also $SHELL variable isn't found anywhere in the script, $serviceUser is another word for root.

3

$HOME is an environment variable that is set on user login. Depending on how you login, the actual program that sets it can vary. If you login by console (including telnet/rlogin/etc), then it will be set by the login program. If you log in by SSH, it will be set by sshd. If you log in using a desktop manager, your desktop manager probably sets it for you.

The reason you need to use -H is to reset the $HOME environment variable when sudoing, so that the other end takes the other user's $HOME, and not the one from the user you are executing sudo as, which some environments allow to propagate.

This, however, is not your real problem. You need a tty when sudo prompts for a password, which you don't have when running a non-interactive script. Considering you got this script from elsewhere, this probably means that this script is either a.) not written correctly, or b.) only written for use when already running as root (perhaps -H here is being used as a roundabout way of trying to sanitise a potentially unclean $HOME, although it's a bit of an odd way of doing so).

I would recommend contacting the author or maintainer.

  • echo $HOME prints out /root and I don't even have that kind of folder. – SSpoke Dec 23 '13 at 3:28
  • @SSpoke You almost certainly do have /root, you just can't see it from an unprivileged user's account. – Chris Down Dec 23 '13 at 3:29
  • I ran $HOME from SSH and this SSH should give me full privileges. I have no idea what $HOME is from the script when the VPS is rebooting – SSpoke Dec 23 '13 at 3:32
  • Ah cd /root goes to ~ which has no folders.., you are saying my SSH doesn't give me full ownership of my VPS? what possible access don't I have? I could install delete anything I want, as well as reinstall the OS. – SSpoke Dec 23 '13 at 3:32
  • I'm not sure what you're saying. You can't "run $HOME", that doesn't really make any sense. I didn't say anything about what ownership this gives you over your VPS, because you've not mentioned anything relevant to that. – Chris Down Dec 23 '13 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.