Why not run crontab?

Source: Internet
Author: User

Key words: crontab, Shell, Y-send, Xauth, xhost

I wrote a script to run it on the terminal:

#! /Bin/ShExport display=:0Time='Awk '{Print $1}'/Proc/Uptime'Text="You have been running for $ {time %. *} hours. Please take a rest. The system will be shut down in 5 minutes. Please save it in time."If[$ {Time%. *}-Ge7200]ThenNotify-Send $ textFi

 

But it cannot be written to crontal:

# M h Dom mon Dow usercommand
* *** Root export display =:0& Amp;/home/XXX/policy.Sh

Why?

 

========================================================

Update: after finding the cause, modify it and OK.

First, you can use/home/cmdy. Sh>/home/log.txt 2> & 1
Deubg to check whether crontab is executed.

I can execute it, but the GUI is not displayed. Why. The display variable settings are incorrect.
However, display =: 0 is added to crontab.

Later, it was mentioned on the Internet that if the GUI is executed on the terminalProgramAfter switching to a user, you must reset the DISPLAY variable to display the data,
The reason is that the. Xauthority file already exists in the/home directory. If you use root to execute this variable, it cannot be displayed without resetting it;
Then I can use the original login user to execute the command, and change it to the following:

# M h Dom mon Dow usercommand*****Xxx(Myname)Export display =:0/Home/XXX/notify.Sh

Success!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.