In the previous posts I had shown How to....
- How to Install MongoDB on Ubuntu 16.04
- Failed to start mongod.service unit mongod.service not found. ubuntu 16.04
- How To Install WordPress, Apache, MySQL and PHP on Ubuntu 16.04
OutPut:
2017-06-10 21:35:01.655477
2017-06-10 21:36:01.686346
2017-06-10 21:37:01.711900
2017-06-10 21:38:01.740353
2017-06-10 21:39:01.767497
2017-06-10 21:40:01.792622
2017-06-10 21:41:01.823149
import datetime
def show_datetime():
print(datetime.datetime.now())
show_datetime
Now run this python file in the terminal to check expected output.
python home/vara/show_time.py
Now to Allow this file as Executing program
sudo chmod +x home/vara/show_time.py
Now In the Terminal open cron job with the below command.
sudo crontab -e
Now Copy paste the below code in the cron tab accordingly and save it.
* * * * * /home/vara/show_time.py >> /home/vara/showtime.log 2>&1
The above cronjob will execute automatically for every 1min and writes the out put in the log file.
Here You may get the error as shown
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
/home/vara/show_time.py: 5: /home/vara/show_time.py: Syntax error: "(" unexpected
To resolve the above error just add #!/usr/bin/env python in 1st line of python file.
#!/usr/bin/env python
import datetime
def show_datetime():
print(datetime.datetime.now())
show_datetime
No comments:
Post a Comment