LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy command wont work if run from Alt-F2 (https://www.linuxquestions.org/questions/linux-newbie-8/copy-command-wont-work-if-run-from-alt-f2-4175661185/)

ddenial 09-20-2019 01:57 AM

Copy command wont work if run from Alt-F2
 
Hello

This is a part in my shell script - which basically compares two files and if they are different, overwrites the other

Code:

if ! cmp --silent /backup/libffmpeg.so /usr/lib64/opera/libffmpeg.so ; then
      notify-send "Different"
      sudo cp -af /backup/libffmpeg.so /usr/lib64/opera/libffmpeg.so
fi

If I tun this script from a terminal, the cp command works perfectly. But if I run this script from Alt-F2 the scripts enter 'if' loop, executes the notify-send command, however, won't copy/replace the file.

Why is it so? How do I correct this?

Thanks

pan64 09-20-2019 02:58 AM

you need to add set -xv to your script and save the output somewhere (to check what's happening).

Firerat 09-20-2019 07:34 AM

my guess is you can't input password for sudo

visudo if you know what you are doing, or

try

gksudo instead of sudo

that should popup a password prompt
but I've never tried it via Alt+F2

ddenial 09-20-2019 08:22 AM

Quote:

Originally Posted by pan64 (Post 6038487)
you need to add set -xv to your script and save the output somewhere (to check what's happening).

I added that in my script. When I run the script from terminal everything works perfectly, but when I run from Alt-F2, don't know where the debug info is visible. Tried running with >& sometextfile.txt, but that doesn't work either.

ddenial 09-20-2019 08:29 AM

Quote:

Originally Posted by Firerat (Post 6038585)
my guess is you can't input password for sudo

visudo if you know what you are doing, or

try

gksudo instead of sudo

that should popup a password prompt
but I've never tried it via Alt+F2

So I I removed 'sudo' from the script and this is what I did
Code:

ls -l /usr/local/bin/post-opera-update
-rwxr-xr-x. 1 root root 651 Sep 20 18:47 post-opera-update

# vim /etc/sudoers
myusername ALL=(ALL) NOPASSWD: /usr/local/bin/post-opera-update,/usr/sbin/nethogs enp3s0

Still not working. OS is CentOS 7.6

ehartman 09-20-2019 08:30 AM

Quote:

Originally Posted by ddenial (Post 6038606)
but when I run from Alt-F2, don't know where the debug info is visible. Tried running with >& sometextfile.txt, but that doesn't work either.

Probably your Alt-F2 (I don't know that one, is that from a file manager?) isn't using a shell so "shell things" like redirection aren't handled BY it.

pan64 09-20-2019 08:31 AM

yes, would be nice to know what do you mean by Alt-F2.

Firerat 09-20-2019 08:40 AM

ahh, Alt+F2 brings up a quick command line on , gnome I think

other desktops may do it

Quote:

Originally Posted by ddenial (Post 6038610)
So I I removed 'sudo' from the script and this is what I did
Code:

ls -l /usr/local/bin/post-opera-update
-rwxr-xr-x. 1 root root 651 Sep 20 18:47 post-opera-update

# vim /etc/sudoers
myusername ALL=(ALL) NOPASSWD: /usr/local/bin/post-opera-update,/usr/sbin/nethogs enp3s0

Still not working. OS is CentOS 7.6

so, you removed sudo from the script
edited sudoers for no password on that script


did you run the script with sudo in the Alt+F2?

pan64 09-20-2019 08:43 AM

Quote:

Originally Posted by ddenial (Post 6038606)
I added that in my script. When I run the script from terminal everything works perfectly, but when I run from Alt-F2, don't know where the debug info is visible. Tried running with >& sometextfile.txt, but that doesn't work either.

you need to specify full path (at least for that textfile) and you will definitely know where is it located.

ddenial 09-20-2019 08:44 AM

1 Attachment(s)
ALT-F2 - Run Command in Gnome desktop.

Output is
0 -rw-rw-r--. 1 user user 0 Sep 20 15:49 debg.txt

Firerat 09-20-2019 08:47 AM

Quote:

Originally Posted by pan64 (Post 6038622)
you need to specify full path (at least for that textfile) and you will definitely know where is it located.

that could also be it

cmp and sudo may need full paths

I'm not sure where teh alt+F2 gets its env. from

I can't really test as I don't have .. I may have gnome on laptop

pan64 09-20-2019 08:53 AM

also try full path for your script. (obviously) that is not the "current" directory, but another one (some default).

ddenial 09-20-2019 08:56 AM

Quote:

Originally Posted by Firerat (Post 6038619)
did you run the script with sudo in the Alt+F2?

Yes. Same result.

Firerat 09-20-2019 09:01 AM

you will also need to redirect stderr


2>&1

sends stderr to stdout

ddenial 09-20-2019 09:03 AM

Quote:

Originally Posted by pan64 (Post 6038627)
also try full path for your script. (obviously) that is not the "current" directory, but another one (some default).

Not working, because post lines after cp are executed, in this case Opera is opened.

My script
Code:

cat /usr/local/bin/post-opera-update
#!/bin/bash
set -xv
### Check libffmpeg.so is same after Opera is updated. Need this to run videos in Opera
if ! cmp --silent /backup/libffmpeg.so /usr/lib64/opera/libffmpeg.so ; then
        cp -af /backup/libffmpeg.so /usr/lib64/opera/libffmpeg.so
fi

### Run Opera
/usr/bin/opera --start-maximized 2> /dev/null &
set +xv


# ll /backup/libffmpeg.so /usr/lib64/opera/libffmpeg.so
 13M -rwxr-xr-x. 1 root root  13M Sep 20 19:22 /backup/libffmpeg.so
1.7M -rwxr-xr-x. 1 root root 1.7M Sep 20 16:33 /usr/lib64/opera/libffmpeg.so



All times are GMT -5. The time now is 03:45 AM.