LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-23-2018, 10:11 PM   #1
w00tus
Member
 
Registered: Jun 2017
Location: Mars on the first shuttle available.
Distribution: Debian, Kali, Raspbian
Posts: 44
Blog Entries: 4

Rep: Reputation: Disabled
Raspbian on 3B (not +), cron refusing to run shell script?


Hello all!

I have what I'm certain is a simple issue.. I've put together two Raspberry Pis to use as thin clients to connect to Windows (shudders) Server Data Center edition. The issue as of now has nothing to do with Microblasphemy, fortunately. (ONE dod gamned program that is PARAMOUNT to the daily operations will ONLY run on Windows or Mac. I don't have anywhere close to the time necessary to mess with Wine and as far as I can tell there is no alternative that has all we need. It's "Phorest" salon software. I had Debian Stretch on this thing originally and it all worked BEAUTIFULLY. Painstaking effort I put into getting it all nice, pretty and autonomous..)

I'm using rdesktop on the pis, have the relative settings correct on the server.

My issue is that cron refuses to run a shell script at a scheduled time (or even every minute if I put all *'s for testing).

Cron is running, I added it to the startup script rc.local. I greped it at every boot to make certain that it was running.

The script, rdp.sh, I've made is a simple one:
Code:
#!/bin/bash
#I just thought, as I'm typing this, that perhaps it should have been "/bin/sh"
rdesktop 192.168.0.21 -f -u breakroom
I've put it in /home/pi/bin, /etc/crond (I think, I'm not at my work bench right now) and every other folder I saw mentioned on any site anywhere that said anything about where these things should go. No dice.

If I type that command, verbatim, in a terminal - rdesktop fires up at breakneck speed and works like a beast. If I double click on the script, click on "run in terminal," it works like a beast. I made it executable with both
Code:
chmod +x rdp.sh
and

Code:
chmod u+x rdp.sh
on another try while I was changing one variable at a time to see what the fudge I was doing wrong. No difference. Works from double click, not from crontab.

I've been using

Code:
crontab -e
to edit the cron table, though I've also tried "sudo crontab -e" as another changed out variable.

The lines I've tried in the crontab file are as follows:

Code:
* * * * * /home/pi/bin/rdp.sh
Code:
* * * * 1-6 /home/pi/bin/rdp.sh
#I was using this today, a Tuesday
Code:
* * * * 1,2,3,4,5,6 /home/pi/bin/rdp.sh
Code:
* * * * * rdp.sh
Code:
* * * * * ./rdp.sh
Code:
* * * * * /rdp.sh
I alternated putting "pi" as the user between the times and paths even though I read in multiple places that this was unnecessary.

I have alternated putting the following right before the schedules:

Code:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Code:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Code:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/pi/bin
Code:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/pi/bin
This was all after trying all of this, but saving the script in the root folder and running it while logged in as another user without sudo privileges to keep other employees that like to mess with things they understand even less than I do. I've got about 9 hours solid invested in this single stupid issue.

I gave up on that.

I also at some point gave up on the pipe dream of running a script. So I tried just putting the command as a scheduled cron job..

Code:
* * * * * rdesktop 192.168.0.21 -f -u breakroom
Code:
* * * * * 'rdesktop 192.168.0.21 -f -u breakroom'
Code:
* * * * * "rdesktop 192.168.0.21 -f -u breakroom"
Code:
* * * * * rdesktop 192.168.0.21
Code:
* * * * * 'rdesktop 192.168.0.21'
Code:
* * * * * "rdesktop 192.168.0.21"
Code:
* * * * * pi rdesktop 192.168.0.21 -f -u breakroom
Code:
* * * * * pi 'rdesktop 192.168.0.21 -f -u breakroom'
Code:
* * * * * pi "rdesktop 192.168.0.21 -f -u breakroom"
As I said, I spent 9 hours on this project save 30 minutes that I took to run to wally world to get new 2.4 amp power supplies just in the off chance that the low power icon I was getting at the top right might have some magical effect on cron not working. Also read that this icon can pop up even when low voltage/amperage is not an issue.

Somewhere, deep in my memory I have what seems to be half a ghost image of a memory that somewhere I read that you have to run a command to update cron after altering crontab. I've read tons of places that it does so automatically.. I have no idea.

Does anyone have any suggestions? I may or may not have time to revisit this tomorrow, the day after or in the next decade the way things are going.. But I would greatly appreciate any help/suggestions/etc.. I'll read them on my phone when I get to go to the bathroom and try them as soon as I can.

Thanks!
 
Old 10-23-2018, 10:37 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
A cron job is not associated with the desktop so you need to specify the display number.

Code:
* * * * * export DISPLAY=":0.0" && /path/to/rdesktop 192.168.0.21 -f -u breakroom
 
1 members found this post helpful.
Old 10-24-2018, 10:42 AM   #3
w00tus
Member
 
Registered: Jun 2017
Location: Mars on the first shuttle available.
Distribution: Debian, Kali, Raspbian
Posts: 44

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
Holy smokes, THANK YOU!!! (I didn't know that about cron, I have much to read..)

I'll be able to try that in about an hour or so.

Also, how do I add rep points to your profile?

*edit a little while later*

That worked flawlessly!!!

(In case another noob like me googles this thread - taking michaelk's advice, I changed my crontab line to:
Code:
* * * * * export DISPLAY=":0.0" && /usr/bin/rdesktop 192.168.0.21 -f -u breakroom
That allowed me to easily test it, as it connected every minute on the minute.

I got the path to rdesktop (I suppose this work work with anything) by typing:

Code:
type rdesktop
And that gave me the path to it!

Last edited by w00tus; 10-24-2018 at 10:57 AM. Reason: Added comment.
 
Old 10-24-2018, 05:46 PM   #4
w00tus
Member
 
Registered: Jun 2017
Location: Mars on the first shuttle available.
Distribution: Debian, Kali, Raspbian
Posts: 44

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
Also, I have a secondary question. I thought I could do this on the server side.. But no easy dice. If it's going to be hard, I'd rather learn how to do it on Linux.

I'm assuming this would be best dealt with in the rdp.sh script.

How would I make the rdesktop session automatically shut down at a specified time?
 
Old 10-24-2018, 08:42 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
Have you tried killing the process?
 
Old 10-25-2018, 06:22 PM   #6
w00tus
Member
 
Registered: Jun 2017
Location: Mars on the first shuttle available.
Distribution: Debian, Kali, Raspbian
Posts: 44

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Have you tried killing the process?
I haven't, no. Does every application have a different PID # every time it loads and/or the machine reboots? If not, sweet! But if so, is there any way to give it a "static id?" Or am I way over thinking this?

Last edited by w00tus; 10-25-2018 at 06:24 PM. Reason: Thought of a better way to phrase the reply that sounds more of the appreciation I feel for the help.
 
Old 10-25-2018, 07:00 PM   #7
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by w00tus View Post
I haven't, no. Does every application have a different PID # every time it loads and/or the machine reboots? If not, sweet! But if so, is there any way to give it a "static id?" Or am I way over thinking this?
You can't predict the PID a process will get. But if this is the only process on the system named "rdesktop", you can kill it by name:
Code:
pkill rdesktop
If not, you have to do additional work to determine the PID. For example, in your script, you could run rdesktop in the background if that is possible, and save its PID to a file:
Code:
#!/bin/bash
rdesktop 192.168.0.21 -f -u breakroom &
echo $! > /var/run/rdesktop.pid

Last edited by berndbausch; 10-25-2018 at 07:03 PM.
 
Old 10-27-2018, 11:16 AM   #8
w00tus
Member
 
Registered: Jun 2017
Location: Mars on the first shuttle available.
Distribution: Debian, Kali, Raspbian
Posts: 44

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You can't predict the PID a process will get. But if this is the only process on the system named "rdesktop", you can kill it by name:
Code:
pkill rdesktop
That.. Is amazing. I never knew that! I thought I always had to tin the pid.
Quote:
Originally Posted by berndbausch View Post
If not, you have to do additional work to determine the PID. For example, in your script, you could run rdesktop in the background if that is possible, and save its PID to a file:
Code:
#!/bin/bash
rdesktop 192.168.0.21 -f -u breakroom &
echo $! > /var/run/rdesktop.pid
That's also super cool. I'm going to read more about the echo command. I've been taking it for granted, just copying what I see in tutorials and not really understanding exactly what it does.

Thank you so much!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script does not run properly from cron daemon Ujio Linux - Newbie 6 07-13-2016 12:32 AM
[SOLVED] Shell script doesn't run on cron (otherwise it works) kalashari Linux - Software 6 02-17-2012 01:50 PM
Cron wont run my shell script shelb Linux - Desktop 4 05-27-2007 09:55 PM
run shell script on cron varunbihani Linux - Newbie 5 07-08-2005 01:50 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration