H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Raspberry Pi problems after modifying crontab

Wed Jul 01, 2020 6:54 pm

Hi, here is the description of the problem.

What I did:
I have written a server in C++ and compiled it. I wanted it to run on startup. The first tutorial I found used crontab. I was connected with SSH and I did this in the terminal:
>> crontab -e
chose nano
added the following line to the bottom
@reboot /path/to/server/

Then, I had to test it. So I decided to reboot the raspberry, and ran the following command:
>> sudo reboot -h now
The SSH disconnected, and then I couldn't connect anymore.
I unplugged the MicroUSB from raspberry, connected the raspberry to a monitor and connected the mouse and keyboard, and plugged the MicroUSB back.
Here is what happens when I start the raspberry.

What happened:
1. At first, I don't remember exactly, but I think the same things specifed in 2 and 3 happened, and I just kept pressing Ctrl + C and the terminal opened in the end. I was stuck in a read-only file system so I decided to fix the inodes using fsck. With
>> fsck /. Then I rebooted and I still don't know if it changed something.
2. some messages print up, and they don't seem suspicious.
3. a bunch of errors shows up:
https://imgur.com/UoVsZfJ
The last message, says that it is trying to start 2 jobs. And after 1 minute and 30 seconds, it proceeds.
Then I get other messages:
https://imgur.com/JkMaJ5D
Just in the end, it logs in the raspberry and boots.
4. Finally, the GUI shows, but then I get a no session for PID error. The keyboard and mouse won't work. Note that the keyboard works before the GUI showing up. I can't connect to the Raspberry via SSH.


What I tried:
I tried to change the crontab file back to its previous state. I opened the contents of the SD card on another PC.
I opened the text file /var/spool/cron/crontabs/pi and removed the line I had added (which was @reboot /path/to/server/).
But the problem is still there. I just removed the server file, so that anything should run it, failing to find the file proceeds without running anything. I haven't still tried to see if this one changed anything.


This is all. What additional information should I provide? I will post updates in this thread.
Thank you in advance for the help.
Hayk.

Update
I removed my server file (deleted it). And the errors are still there.
In the very end, it waits for 3 jobs to complete. One relates to random, and it completes, the other 2 do not.
Here are the other 2 jobs:
A start job is running for /dev/serial1
And
/dev/disk/by-partuuid/4ef487da-01

This is probably because the dev folder is empty.
Last edited by H-a-y-k on Sat Jul 04, 2020 6:39 am, edited 9 times in total.

renice123
Posts: 198
Joined: Tue Oct 15, 2019 3:56 pm

Re: Raspberry pi not seeing keyboard and mouse. Ssh not working as well.

Fri Jul 03, 2020 6:56 am

Your problem is very similar to the problem with the memory card. Try to put another memory card with a new operating system. Sometimes memory cards begin to “break” when some files disappear or programs do not start.

bjtheone
Posts: 862
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Raspberry pi not seeing keyboard and mouse. Ssh not working as well.

Fri Jul 03, 2020 1:44 pm

It sounds like your server is not starting properly and so the boot process is hanging and not completing fully.

A couple of questions:

* does your server start when executed from the command line?
* what user does your server run as (pi or root)?
* what user's crontab did you put the startup command in?
* what environmental variables does your server need to start correctly? (PATH may be different)

and a suggestion:

Add logging so you can see what is happening. Something like:

01 14 * * * /home/pi/myscript >> /home/pi/log/myscript.log 2>&1

H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Re: Raspberry Pi problems after modifying crontab

Fri Jul 03, 2020 6:27 pm

Thank you for the replies. I thought I would be notified, so I hadn't noticed your replies, I apologize for that.
I rewrote the description and changed the title. Now I think it is clearer and more detailed.

H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Re: Raspberry pi not seeing keyboard and mouse. Ssh not working as well.

Fri Jul 03, 2020 6:37 pm

bjtheone wrote:
Fri Jul 03, 2020 1:44 pm
It sounds like your server is not starting properly and so the boot process is hanging and not completing fully.

A couple of questions:

* does your server start when executed from the command line?
* what user does your server run as (pi or root)?
* what user's crontab did you put the startup command in?
* what environmental variables does your server need to start correctly? (PATH may be different)

and a suggestion:

Add logging so you can see what is happening. Something like:

01 14 * * * /home/pi/myscript >> /home/pi/log/myscript.log 2>&1
Thank you for your reply.
Yes, I also think so, I also added some updates in the new description.

1. Yes, I tried executing the server even outside the folder it's located in, and it started fine.
2. I am not sure, how can I check that? I suppose pi.
3. probably pi. I mean, I just did
>> crontab -e in the default user (which is pi).
4. In order to run it, no environment variables are needed. The only time I need them is during compilation, which is just for the libraries the program uses.

For the suggestion: okay, thanks, I will do that and let you know.
Last edited by H-a-y-k on Fri Jul 03, 2020 6:47 pm, edited 1 time in total.

H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Re: Raspberry pi not seeing keyboard and mouse. Ssh not working as well.

Fri Jul 03, 2020 6:38 pm

renice123 wrote:
Fri Jul 03, 2020 6:56 am
Your problem is very similar to the problem with the memory card. Try to put another memory card with a new operating system. Sometimes memory cards begin to “break” when some files disappear or programs do not start.
For now I prefer not to do that, as this is not my own raspberry.
But still, thank you for your reply!

H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Re: Raspberry Pi problems after modifying crontab

Sat Jul 04, 2020 6:34 am

Update
I removed my server file (deleted it). And the errors are still there.
In the very end, it waits for 3 jobs to complete. One relates to random, and it completes, the other 2 do not.
Here are the other 2 jobs:
A start job is running for /dev/serial1
And
/dev/disk/by-partuuid/4ef487da-01

This is probably because the dev folder is totally empty.

H-a-y-k
Posts: 6
Joined: Wed Jul 01, 2020 6:31 pm

Re: Raspberry Pi problems after modifying crontab

Sat Jul 25, 2020 12:02 pm

SOLUTION

Finally, I found the solution to the problem.
Ironically, it had nothing to do with crontab. The modification of crontab and these sudden problems were just a mere coincidence.
The problem appeared after a recent dist-upgrade I had done. It is caused by raspi-copies-and-fills. On some forums, it is suggested to do apt purge raspi-copies-and-fills.
I did different though, I followed the instructions on this page https://raspberrypi.stackexchange.com/q ... m-raspbian.
I hope this will be of help :)

mpratt14
Posts: 27
Joined: Tue Feb 11, 2020 10:10 am

Re: Raspberry Pi problems after modifying crontab

Mon Jul 27, 2020 1:55 pm

for the record I have not had good luck with @reboot with cron on my Pi 4. instead I have the task run every minute with an if statement.

Spile
Posts: 7
Joined: Wed Jul 22, 2020 5:57 am
Location: Worcestershire

Re: Raspberry Pi problems after modifying crontab

Mon Jul 27, 2020 3:19 pm

I had a problem with using @reboot in a crontab. I resolved it by adding a delay that allowed the pi to complete its network connection...
@reboot sleep 60 && [instructions here]

Return to “Troubleshooting”