Script won't work correctly unless launched from a log in shell.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Script won't work correctly unless launched from a log in shell.
The simple script below will not pass the value to the file used for the variable unless I launch it directly from the shell. The file used to host to data is open wide at 0777 permission. I attempted to launch as part of my start up script ( ~.config/openbox/autostart ) as well as assigning to a key bind to launch and no dice. The script runs but does not write the data to the file so the screen pop only includes the text I have entered.
Any thoughts would be appreciated.
Code:
#! /bin/bash
# Geeknote -- screen pop of selected notes : site -- http://geeknote.me/
STRING="*" # String Search in Note
TAG="To-do" # Note Tag Example : Development , To-do
NB="Master" # Notebook
INTERVAL=15 # Pop cylce in minutes
# setting time to zero keeps image up until clicked.
while [ 1 ]
do
geeknote find --search "$STRING" -tg "$TAG" -nb "$NB" | egrep [[:blank:]][0-9][0-9] > /media/N-Space/home/joe/.geeknote/list
VAR=$(cat /media/N-Space/home/joe/.geeknote/list)
xcowsay --monitor=1 --cow-size=small --at=550,5 -l --font="Sans Droid 10.5" --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png "
Active notes as of $(date +%F-%r) :
-------------------------------------------------------------
$VAR"
sleep "$INTERVAL"m
done
my best guess is that its not starting at all from the autostart script. try using the ps command to verify. perhaps the command previous to it in the script is not being backgrounded, or there is a syntax error. try adding something you know will work after this scripts line in the text in order to verify that the script is actually getting executed all the way through.
i could be wrong, but i am pretty sure that even if the script is not launched directly from a login shell, it is launched within the shell of whatever program spawned it resides in, so all the environment variable and bash syntax should work.
Last edited by nd7rmn8; 01-01-2014 at 10:18 AM.
Reason: clarification
The script launches fine either method. If ran from the command prompt it pulls down the data , writes to a file and assigns to a variable so it can get posted to the screen.
If ran by the start up file it only posts the fixed header I have in the script. Both logs highlights an error around the theme but does not effect if ran from the command prompt .
Log from script running from command prompt:
Code:
set -x
STRING="*" # String Search in Note
+ STRING='*'
TAG="To-do" # Note Tag Example : Development , To-do
+ TAG=To-do
NB="Master" # Notebook
+ NB=Master
INTERVAL=15 # Pop cylce in minutes
+ INTERVAL=15
# setting time to zero keeps image up until clicked.
while [ 1 ]
do
geeknote find --search "$STRING" -tg "$TAG" -nb "$NB" | egrep [[:blank:]][0-9][0-9] > /media/N-Space/home/joe/.geeknote/list
VAR=$(cat /media/N-Space/home/joe/.geeknote/list)
xcowsay --monitor=1 --cow-size=small --at=550,5 -l --font="Sans Droid 10.5" --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png "
Active notes as of $(date +%F-%r) :
-------------------------------------------------------------
$VAR"
sleep "$INTERVAL"m
done
+ '[' 1 ']'
+ geeknote find --search '*' -tg To-do -nb Master
+ egrep '[[:blank:]][0-9][0-9]'
cat /media/N-Space/home/joe/.geeknote/list)
cat /media/N-Space/home/joe/.geeknote/list
++ cat /media/N-Space/home/joe/.geeknote/list
+ VAR=' 1 : 30.12.2013 Debug Lan-Kill Script
2 : 30.12.2013 Kismet
3 : 29.12.2013 System Exception : Geek Note
4 : 29.12.2013 Small Engine : PM'\''s
5 : 29.12.2013 Repair Shed
6 : 29.12.2013 Monthly -- Mirror Update
7 : 29.12.2013 Innotab -- Videos
8 : 29.12.2013 Desktop Admin -- Cases'
date +%F-%r) :
date +%F-%r) :
date +%F-%r
++ date +%F-%r
+ xcowsay --monitor=1 --cow-size=small --at=550,5 -l '--font=Sans Droid 10.5' --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png '
Active notes as of 2014-01-01-06:12:06 PM :
Log from script running from auto-start file:
Code:
set -x
STRING="*" # String Search in Note
+ STRING='*'
TAG="To-do" # Note Tag Example : Development , To-do
+ TAG=To-do
NB="Master" # Notebook
+ NB=Master
INTERVAL=15 # Pop cylce in minutes
+ INTERVAL=15
# setting time to zero keeps image up until clicked.
while [ 1 ]
do
geeknote find --search "$STRING" -tg "$TAG" -nb "$NB" | egrep [[:blank:]][0-9][0-9] > /media/N-Space/home/joe/.geeknote/list
VAR=$(cat /media/N-Space/home/joe/.geeknote/list)
xcowsay --monitor=1 --cow-size=small --at=550,5 -l --font="Sans Droid 10.5" --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png "
Active notes as of $(date +%F-%r) :
-------------------------------------------------------------
$VAR"
sleep "$INTERVAL"m
done
+ '[' 1 ']'
+ egrep '[[:blank:]][0-9][0-9]'
+ geeknote find --search '*' -tg To-do -nb Master
cat /media/N-Space/home/joe/.geeknote/list)
cat /media/N-Space/home/joe/.geeknote/list
++ cat /media/N-Space/home/joe/.geeknote/list
+ VAR=
date +%F-%r) :
date +%F-%r) :
date +%F-%r
++ date +%F-%r
+ xcowsay --monitor=1 --cow-size=small --at=550,5 -l '--font=Sans Droid 10.5' --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png '
Active notes as of 2014-01-01-05:47:12 PM :
-------------------------------------------------------------
'
/media/N-Space/home/joe/.themes/Blue-Joy/gtk-2.0/gtkrc:83: Unable to locate image file in pixmap_path: "../bg3.png"
/media/N-Space/home/joe/.themes/Blue-Joy/gtk-2.0/gtkrc:85: Background image options specified without filename
+ sleep 15m
+ '[' 1 ']'
+ geeknote find --search '*' -tg To-do -nb Master
+ egrep '[[:blank:]][0-9][0-9]'
cat /media/N-Space/home/joe/.geeknote/list)
cat /media/N-Space/home/joe/.geeknote/list
++ cat /media/N-Space/home/joe/.geeknote/list
+ VAR=
date +%F-%r) :
date +%F-%r) :
date +%F-%r
++ date +%F-%r
+ xcowsay --monitor=1 --cow-size=small --at=550,5 -l '--font=Sans Droid 10.5' --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png '
Active notes as of 2014-01-01-06:03:13 PM :
-------------------------------------------------------------
'
/media/N-Space/home/joe/.themes/Blue-Joy/gtk-2.0/gtkrc:83: Unable to locate image file in pixmap_path: "../bg3.png"
/media/N-Space/home/joe/.themes/Blue-Joy/gtk-2.0/gtkrc:85: Background image options specified without filename
+ sleep 15m
Well nothing jumps out but I am wondering if it is a PATH issue to your special commands of geeknote and xcosway?
The 2 things i would try are:
1. Use full path to commands
2. Simplify to the single line that appears to be the issue, namely geeknote (I assume you have checked the output file to confirm there is nothing in it?), and see if just that single line
works in a script run the same way (ie. the one that is not working)
I am guessing you are also aware that there is no need to output to a file as you could replace your cat command with the geeknote one.
Also, I would quote the pattern in egrep, you never know…
My guess would be some environment variables, and I can just echo grail's advice to try and use full paths for the commands, but other then that I'm puzzled.
NevemTeve, yes, space in shebang line is valid on any modern system. Lack of space may be more portable for older systems though.
However ,even though my script is in better shape I still get the same result.
I will have to keep studying
Code:
#! /bin/bash
# Geeknote -- screen pop of selected notes : site -- http://geeknote.me/
STRING="*" # String Search in Note
TAG="To-do" # Note Tag Example : Development , To-do
NB="Master" # Notebook
INTERVAL=15 # Pop cylce in minutes
# setting time to zero keeps image up until clicked.
while [ 1 ]
do
VAR=$(/usr/bin/geeknote find --search "$STRING" -tg "$TAG" -nb "$NB" | egrep "[[:blank:]][0-9][0-9]")
/usr/bin/xcowsay --monitor=1 --cow-size=small --at=550,5 -l --font="Sans Droid 10.5" --time=0 --image=/media/N-Space/home/joe/.geeknote/logo2.png "
Active notes as of $(date +%F-%r) :
-------------------------------------------------------------
$VAR"
sleep "$INTERVAL"m
done
If it still does not work, then I'd dig into geeknote documentation and also compare the environment (i.e. add invocation of “env” somewhere to see all the variables).
PS. An infinite loop is easier typed as “while :; do …; done” plus “:” is always a built in.
As a thought, Evernote requires one to login to access notes and I am guessing at some point you need to login for geeknote to have access??
Is it possible that because geeknote is now not be run under the correct credentials it is returning no data?
It appears (from the documentation) that it uses an interactive connection for login. That normally needs something for a terminal to be attached... Also items like "show", "find" use stdout, implying that stdout exists, even if it might be a pipe.
And for options like "editor" where vim is specified requires that geeknote to pass the attached terminal to the editor of choice.
Now, not having a terminal may not be deliberately required, but just a side effect of assuming one is always attached and available. Trying to pass stdin/stdout/stderr via a fork would get an error unless it is specifically coded to be allowed.
One way that could be tested is to redirect stdin/stdout/stderr - stdin from /dev/null (causes an eof when read) stdout and stderr to a file - thus any error messages would get recorded.
I doubt stdin is the problem, but maybe stdout or stderr could be (especially if the command outputs a status).
if you have screen installed, try placing this in your autostart file in place of the line that calls your script. It will start a new screen session named foo, run the script.sh within that session and then immediately detach it.
Code:
screen -S foo -d -m /path/to/script.sh &
then you can reattach the screen session again later by typing the following into any terminal window.
Code:
screen -r foo
to leave the screen session again press control-a-d.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.