“stdin: is not a tty” from cronjob

孤街醉人 提交于 2019-11-30 21:08:11

You actually have two questions here.

  1. Why it prints stdin: is not a tty?

This warning message is printed by bash -l. The -l (--login) options asks bash to start the login shell, e.g. the one which is usually started when you enter your password. In this case bash expects its stdin to be a real terminal (e.g. the isatty(0) call should return 1), and it's not true if it is run by cron—hence this warning.

Another easy way to reproduce this warning, and the very common one, is to run this command via ssh:

$ ssh user@example.com 'bash -l -c "echo test"'
Password:
stdin: is not a tty
test

It happens because ssh does not allocate a terminal when called with a command as a parameter (one should use -t option for ssh to force the terminal allocation in this case).

  1. Why it did not work without -l?

As correctly stated by @Cyrus in the comments, the list of files which bash loads on start depends on the type of the session. E.g. for login shells it will load /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile (see INVOCATION in manual bash(1)), while for non-login shells it will only load ~/.bashrc. It seems you defined your http_proxy variable only in one of the files loaded for login shells, but not in ~/.bashrc. You moved it to ~/.wgetrc and it's correct, but you could also define it in ~/.bashrc and it would have worked.

in your .profile, change

mesg n

to

if `tty -s`; then
  mesg n
fi

I ended up putting the proxy configuration in the wgetrc. There is now no need to execute the script on a login shell anymore.

This is not a real answer to the actual problem, but it solved mine.

If you run into this problem check if you are getting all the environment variables set as you expect. Thanks to Cyrus for putting me to the right direction.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!