LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-01-2014, 07:58 AM   #1
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Question 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
 
Old 01-01-2014, 10:17 AM   #2
nd7rmn8
Member
 
Registered: Jan 2013
Distribution: Arch
Posts: 50

Rep: Reputation: 13
strange

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
 
Old 01-01-2014, 11:57 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Guess you should do some debugging. Use the following commands in your script:

Code:
exec >/tmp/debug.log.$$ 2>&1
set -v
set -x
PS: is space allowed here?:
Code:
#! /bin/bash
 
Old 01-01-2014, 05:19 PM   #4
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Question

Thanks for everyone's feedback.

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
 
Old 01-01-2014, 08:56 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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.

Last edited by grail; 01-01-2014 at 08:58 PM.
 
Old 01-02-2014, 12:37 AM   #6
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
What if you skip the list file? I.e.:
Code:
VAR=$(geeknote find --search "$STRING" -tg "$TAG" -nb "$NB" | egrep '[[:blank:]][0-9][0-9]')
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.
 
Old 01-02-2014, 06:11 PM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Question

Thank you for all the suggestions !!

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
 
Old 01-02-2014, 09:03 PM   #8
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
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.
 
Old 01-04-2014, 07:06 AM   #9
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Thanks for the help !!!

I'll keep digging and report back if I find something.
 
Old 01-04-2014, 10:25 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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?
 
Old 01-04-2014, 12:17 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I would bet that geeknote requires a terminal attached for it to work.
 
Old 01-04-2014, 05:40 PM   #12
nd7rmn8
Member
 
Registered: Jan 2013
Distribution: Arch
Posts: 50

Rep: Reputation: 13
Quote:
Originally Posted by jpollard View Post
I would bet that geeknote requires a terminal attached for it to work.
if thats the case, maybe attaching it to screen would allow it to work. but why would a process require being ran inside a terminal to work?
 
Old 01-05-2014, 04:11 AM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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).
 
Old 01-05-2014, 10:27 AM   #14
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Good thoughts. However as part of my start up scripts I log in.
 
Old 01-05-2014, 01:39 PM   #15
nd7rmn8
Member
 
Registered: Jan 2013
Distribution: Arch
Posts: 50

Rep: Reputation: 13
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.
 
  


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
respawn from inittab of process launched by a shell script Barx Slackware 2 09-25-2013 08:25 AM
why won't my shell script work :( Sanji Linux - Software 1 04-12-2005 08:10 PM
Kill a process launched by a shell script gsbarry Programming 7 01-06-2004 02:09 PM
Shell script won't work. Why? bruno buys Linux - Newbie 2 11-16-2003 07:28 PM
XF86Config won't work correctly FZJ Linux - General 4 03-01-2003 01:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 PM.

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