jsmecha
Posts: 1
Joined: Wed Sep 05, 2018 4:24 am

[Need Help] PM2 and bash script doesn't run when booting

Wed Sep 05, 2018 7:03 am

I have 3 unresolved problems in my raspberry pi3
So, I need help to know How to fix them.

Problem 1) I used winscp for connecting to raspberry pi for a while. It didn't have any problem, it worked very well.
However, Suddenly, I couldn't connect raspberry pi, which is same one I connected very well just 1 day before.
After authenticated, winscp stuck in "Starting the session". and error message comes out.
The error message is "Cannot Initialize SFTP protocal. Is the host running a SFTP server?"
At the same time, in case of connecting by Putty, It also stuck at the line "Last login: ~~~" (just before showing prompt)
This problem disappear after rebooting raspberry pi. But after a while, it recurs.
The attachment problem1_winscp_2.png is no longer available
The attachment problem1_winscp_2.png is no longer available
The attachment problem1_putty.png is no longer available

Problem 2) This is about bash script and also suddenly happened.
I use PM2 and I made bash script file for starting my Python program automatically when raspberry boot.
Normally, It work well. when I check "sudo pm2 list", my python code is online. but sometimes, It doesn't run
automatically. I guess that bash script doesn't work. I don't know why.
When I run the script manually, it works without error.

Problem 3) This is also about bash script.
I made a bash script for deleting log files in 3 diffrent folders once a day.
'rc.local' call this script and only delete log files in 2 folders except for the last one.
When I run the script manually, it work well and log files in 3 folders are deleted.
Attachments
problem1_putty.png
problem1_putty.png (27.26 KiB) Viewed 190 times

pfletch101
Posts: 629
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: [Need Help] PM2 and bash script doesn't run when booting

Wed Sep 05, 2018 2:54 pm

jsmecha wrote:
Wed Sep 05, 2018 7:03 am
I have 3 unresolved problems in my raspberry pi3
So, I need help to know How to fix them.

Problem 2) This is about bash script and also suddenly happened.
I use PM2 and I made bash script file for starting my Python program automatically when raspberry boot.
Normally, It work well. when I check "sudo pm2 list", my python code is online. but sometimes, It doesn't run
automatically. I guess that bash script doesn't work. I don't know why.
When I run the script manually, it works without error.
A common reason for this sort of behavior is that the program requires a resource (often the network) that is not immediately available on bootup. The usual fix is simply to put a short 'time.sleep()' at the beginning of the script to allow time for the system to be fully initialized before it 'really' starts.
Problem 3) This is also about bash script.
I made a bash script for deleting log files in 3 diffrent folders once a day.
'rc.local' call this script and only delete log files in 2 folders except for the last one.
When I run the script manually, it work well and log files in 3 folders are deleted.
Make sure that the absolute file paths are specified for all the folders and that there is nothing 'funny' about the access privileges of the folder whose files are not being deleted by the rc.local job.

Return to “Troubleshooting”