yo8192 / fcron

fcron is an advanced cron for Linux/Unix systems
http://fcron.free.fr
GNU General Public License v2.0
135 stars 12 forks source link

Can't use editor specified in .conf file on Ubuntu #6

Closed PoLaKoSz closed 4 years ago

PoLaKoSz commented 4 years ago

I am moving from Windows and i would like to use a Windows Task Scheduler like application to schedule some jobs (and wake up my PC if its suspended and put back to sleep after the jobs are done) on my Ubuntu 20.04 machine. I don't have too much experience with Linux environment so i would like to ask for some help because i hit a wall:

Steps to reproduce my issue

i get this:

polakosz@polakosz-Aspire-E3-112:~$ sudo fcrontab -u polakosz -d -c /home/polakosz/.config/fcron.conf -e
[sudo] password for polakosz: 
2020-07-19 19:11:55 DEBUG   fcronconf=/home/polakosz/.config/fcron.conf
2020-07-19 19:11:55  INFO fcrontab : editing polakosz's fcrontab
no fcrontab for polakosz - using an empty one
2020-07-19 19:11:55 ERROR Error while running "/usr/bin/gedit": No such file or directory
2020-07-19 19:11:55 ERROR Could not open file /tmp/fcr-ss0Z5j: No such file or directory
2020-07-19 19:11:55 ERROR could not remove /tmp/fcr-ss0Z5j: No such file or directory
polakosz@polakosz-Aspire-E3-112:~$

if i type /usr/bin/gedit into the Terminal it will open the text editor.

yo8192 commented 4 years ago

Any particular reason why you use sudo to run fcrontab, especially as it looks like you may be asking sudo to run it as yourself?

Now for your question, in http://fcron.free.fr/doc/en/fcrontab.1.html you can read:

-e Edit user's current fcrontab using either the editor specified by the environment variable VISUAL, or EDITOR if VISUAL is not set. If none or them are set, /usr/bin/vi will be used.

Typically sudo will clear (most of) the environment, but can be configured to keep it. Could you please double check these env vars are not set?

e.g. run: env | grep -e VISUAL -e EDITOR and if you do continue to run fcrontab via sudo, then try: sudo -u polakosz env | grep -e VISUAL -e EDITOR

If these command return something, then it will be what fcrontab will use.

To override those, you could look at unsetting them, or maybe more simply (if that's the only thing you were trying to change via your fcron.conf), you could run something as: sudo -u polakosz VISUAL=/usr/bin/gedit fcrontab -e (or without the sudo if you didn't have a good reason to use it)

PoLaKoSz commented 4 years ago

Thank You for the answer. Using sudo is just a bad beginner habit.

polakosz@polakosz-Aspire-E3-112:~$ env | grep -e VISUAL -e EDITOR
polakosz@polakosz-Aspire-E3-112:~$ sudo -u polakosz env | grep -e VISUAL -e EDITOR
polakosz@polakosz-Aspire-E3-112:~$ 

Till this moment i thought these two environment variables was build-in.

To be honest i was able to execute shell scripts with fcron a few days later i posted this issue, but i wanted to know what i did wrong and now i know thanks to You!

One more question not fully related this one: When fcron woke up my machine and executed the shell scripts the machine didn't go back to sleep. Is this intentional? If the answer is yes do You think implementing a feature to put the machine back to sleep could be benefitial? Should i open a new issue for this?

yo8192 commented 4 years ago

fcron has no feature to wake up your machine or put it to sleep. fcron's approach is rather to work-around possibly irregular patterns of machine uptime.

That said, you could maybe try to have schedule jobs to run commands such as systemctl suspend or rtcwake to do something like that (I didn't try myself)

PoLaKoSz commented 4 years ago

Thank You!