when linux system calls scripts some commands don't work ( cron / if-up.d )

620 Views Asked by At

Hi I'm trying to run a script that calls xclip in order to have a string ready to paste when i connect to the internet.

I have a script /etc/network/if-up.d/script that does execute when connecting (i make him post a date in a file succesfuly ) but the xclip instruction seems not to work, there's nothing to paste. If i call this script manually by typing /etc/network/if-up.d/script in a console it works perfectly.

If i try to launch a zenity message it also don't appeare when connecting. Again if i do it by hand it appeares.

Then I have a expect script that calls matlab (console mode), if I execute it manually it works but if i call it from cron it freezees when calling the script.

It's driving me crasy since it seems that only certain commands in a script can be executed when the system calls them automaticaly.

I'v tryed to call the instructions with nohup instruction & but still misses

2

There are 2 best solutions below

0
On

This is working as designed, you search around and will see compliated ways to resolve this issue, or you can use xmessage as I describe here: Using Zenity in a root incron job to display message to currently logged in user

Easy option 1: xmessage (in the script)

MSSG="/tmp/mssg-file-${RANDOM}" 
echo -e " MESSAGE \n ==========\n Done with task, YEY. " > ${MSSG}
xmessage -center -file ${MSSG} -display :0.0 
[[ -s ${MSSG} ]] && rm -f ${MSSG}

Easy option 2: set the DISPLAY (then should work)

    export DISPLAY=:0 && /usr/bin/somedirectory/somecommand
0
On