LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-04-2020, 07:44 PM   #1
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Rep: Reputation: Disabled
Shell Script with curl works on terminal but not as menu launcher.


Hello friends Happy New Year.

I have a question because I have a problem to apply a simple script as a launcher click to execute in terminal and auto use curl that have wttr.in as target.

If I directly put this command on terminal he works →

Code:
$ bash -x /home/joao/.config/tempo.sh
This tempo.sh have this lines →

Code:
#!/usr/bin/env bash
curl  https://wttr.in/chaves
The problem when I try to do a launcher to execute the script he simply open the terminal and do nothing. Here is the launcher sintax →

Code:
[Desktop Entry]
Name=Tempo-Chaves
Exec=bash -c /home/joao/.config/tempo.sh
Comment=
Icon=
NoDisplay=false
Type=Application
Terminal=true
Categories=Utility;
I already try chage the Exec line with this →

Exec=/usr/bin/bash -c /home/joao/.config/tempo.sh

Exec=/usr/bin/env bash -c /home/joao/.config/tempo.sh

Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh;$bash' "

...

So now i'm curious why script works if I directly use the command with path on terminal but not as a launcher.

Thanks.
 
Old 01-04-2020, 08:08 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,211

Rep: Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912
Try providing the full path to curl in the script...
 
Old 01-05-2020, 05:07 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 15,503
Blog Entries: 9

Rep: Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466Reputation: 4466
is tempo.sh marked executable?
Code:
chmod +x tempo.sh
 
Old 01-05-2020, 05:30 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,125
Blog Entries: 3

Rep: Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548
Quote:
Originally Posted by ondoho View Post
is tempo.sh marked executable?
Code:
chmod +x tempo.sh
That would be the first thing to check.

The second would be to have it use the interpreter directly instead of depending on an indirect reference from the environment:

Code:
#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/bin

curl https://wttr.in/chaves
The $PATH part is optional but often a good idea for scripts which will be used in an automated manner.

Then invoke the script like this:

Code:
Exec=/home/joao/.config/tempo.sh
And one more thing, the placement of your script would be better /home/joao/bin/ instead. Everything has a place. If you need the output of curl to be within /home/joao/.config/ then you can save it there:

Code:
#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/bin

curl https://wttr.in/chaves > /home/joao/.config/chaves
 
Old 01-05-2020, 09:16 AM   #5
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
That would be the first thing to check.

The second would be to have it use the interpreter directly instead of depending on an indirect reference from the environment:

Code:
#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/bin

curl https://wttr.in/chaves
The $PATH part is optional but often a good idea for scripts which will be used in an automated manner.

Then invoke the script like this:

Code:
Exec=/home/joao/.config/tempo.sh
And one more thing, the placement of your script would be better /home/joao/bin/ instead. Everything has a place. If you need the output of curl to be within /home/joao/.config/ then you can save it there:

Code:
#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/bin

curl https://wttr.in/chaves > /home/joao/.config/chaves
I try all your suggestions and dont work the comman /home/joao/.config/tempo.sh or /home/joao/bin/tempo.sh specified directly on terminal works but in a launcher only opens terminal and do nothing.

I edit the file like this →

#!/usr/bin/env bash
PATH=/usr/local/bin:/usr/bin:/bin
curl https://wttr.in/chaves

And I try to put the file on a /bin path on my current user and I also modify the launcher Exec command.

No work.

Of course I already check the permission execution mentioned on command → chmod +x ...

Thanks for help.
 
Old 01-05-2020, 09:18 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,330

Rep: Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032
I would add some echo commands to that script, like echo started.
And also I would redirect its output into a logfile.
Adding set -xv at the beginning also may help (to find the reason).
 
Old 01-05-2020, 10:13 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,522

Rep: Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589
It does work, you just can't see it.

I assume when you click on the shortcut, a terminal window opens, appears to do nothing and then closes.

This is normal.

Quote:
curl https://wttr.in/chaves > /home/joao/.config/chaves
With this command the terminal will still open and appear to do nothing but the output will be written to a file. I would pick another location but it should still work.

If you want to see the output in the terminal window you need to pause your running script
Code:
#!/bin/bash

curl https://wttr.in/chaves
read -p "Press any key to continue"

Last edited by michaelk; 01-05-2020 at 10:30 AM.
 
Old 01-05-2020, 10:31 AM   #8
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Original Poster
Rep: Reputation: Disabled
I Tried the code script →

#!/bin/bash

curl https://wttr.in/chaves
read -p "Press any key to continue"

And still do nothing the "Press any key to continue" dont appear also and the terminal open and do nothing.
 
Old 01-05-2020, 10:41 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,522

Rep: Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589
Does the script still work from the command line but not the launcher?

As a frame of reference I am testing your script on Ubuntu version 19.
 
Old 01-05-2020, 10:59 AM   #10
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Does the script still work from the command line but not the launcher?

As a frame of reference I am testing your script on Ubuntu version 19.
Yes in command line directly works well on launcher not.
 
Old 01-05-2020, 11:26 AM   #11
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,330

Rep: Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032
how do you know that?
 
Old 01-05-2020, 11:38 AM   #12
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
how do you know that?
In terminal you target the script in my case now I have two paths :
/home/joao/.config/tempo.sh
/home/joao/bin/tempo.sh

the content of scripth (.sh file) is →

Code:
#!/bin/bash

curl https://wttr.in/chaves
read -p "Press any key to continue"
When I open a terminal like lxterminal and put the target script he runs →

$/home/joao/.config/tempo.sh

You can test this on your system copy the script, put on a file .txt like tempo.txt, rename the file to .sh like tempo.sh view permissions or pass the chmod command to the file execution permissions - chmod +x /path/to/your/file.sh.
Copy te file and put on a path of your current user /home/user/tempo.sh or ~ /tempo.sh and run it (~ - means your current user folder - home).

So because this I can see the script works when I run it specifiyng directly the path on terminal but for some reason when I do a a launcher to be executed in terminal he dont works.

Last edited by portaro; 01-05-2020 at 11:41 AM.
 
Old 01-05-2020, 11:50 AM   #13
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,330

Rep: Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032
Because the launcher does not use any terminal (you will not see the result in your terminal).
You need to save the downloaded content as it was suggested in post #4 and/or you can add debug info (post #6).
Also you can specify a terminal in the Exec line, something like this:
Code:
Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh' "
but you ought to try this command in your terminal if works
 
Old 01-05-2020, 12:07 PM   #14
portaro
Member
 
Registered: Mar 2015
Location: Portugal
Distribution: Ubuntu
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Because the launcher does not use any terminal (you will not see the result in your terminal).
You need to save the downloaded content as it was suggested in post #4 and/or you can add debug info (post #6).
Also you can specify a terminal in the Exec line, something like this:
Code:
Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh' "
but you ought to try this command in your terminal if works
In fact I already try the Exec line that you post I put on the first post a similar launcher execution →

Exec=lxterminal -e "bash -c '/home/joao/.config/tempo.sh;$bash' "

Dont work on launcher open terminal only do nothing.

In terminal here the outputs →
$ "bash -c '/home/joao/.config/tempo.sh' "bash: bash -c '/home/joao/.config/tempo.sh' : Ficheiro ou directoria inexistente

$ bash -c '/home/joao/.config/tempo.sh'
Weather report: chaves ... → works fine
 
Old 01-05-2020, 01:31 PM   #15
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,330

Rep: Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032Reputation: 5032
yes, what you entered is wrong. You need to modify it. That's why I told you to test it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script with Menu and sub menu and in sub menu execute another shell script SHWE Linux - Newbie 9 11-03-2018 06:19 PM
[SOLVED] firefox launcher doesn't show icon on panel bar of slackware but launcher still there mshlinux Linux - Newbie 6 04-24-2013 10:56 PM
cURL: Server has many IPs, how would I make a cURL script use those IPs to send data? guest Programming 0 04-11-2009 11:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:39 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