Bash script acts differently depending on what executes it - bash

I have a bash script which acts as a post-process script for utorrent-server that passes on variables to a media renamed called FileBot.
Script:
#!/bin/bash
TORRENT_NAME=$1
TORRENT_PATH=$2
TORRENT_LABEL=$3
TORRENT_KIND=$4
TORRENT_TITLE=$5
/usr/share/filebot/bin/filebot.sh -script fn:amc --output "/mnt/Storage/" \
--log-file "amc.log" --action move --conflict override -non-strict \
--def music=n subtitles=en artwork=n xbmc="192.168.0.123" deleteAfterExtract=y \
clean=y "ut_dir=$TORRENT_PATH" "ut_file=$TORRENT_NAME" "ut_kind=$TORRENT_KIND" \
"ut_title=$TORRENT_TITLE" "ut_label=$TORRENT_LABEL" "ut_state=5" "seriesFormat=TV \
Shows/{n}/Season {s.pad(2)}/{n} - {s00e00} - {t}" "movieFormat=Movies/{n} ({y})/{n} ({y})" \
&>> /home/xbmc/run.log
If i run this script manually, it works as intended, however when uTorrent executes it, it returns "No such file or directory." via stderr. I originally had uTorrent calling this script directly however I was having the same issue.
Does anyone know what could cause this?
UPDATE (Permissions for all directories/folders):
drwxr-xr-x 3 root root 4096 Nov 27 23:52 /home
drwxr-xr-x 20 xbmc xbmc 4096 Dec 15 21:46 /home/xbmc
drwxr-xr-x 10 root root 4096 Oct 17 06:51 /usr
drwxr-xr-x 218 root root 4096 Dec 13 15:32 /usr/share
drwxr-xr-x 3 root root 4096 Dec 15 15:55 /usr/share/filebot
drwxr-xr-x 2 root root 4096 Dec 15 18:56 /usr/share/filebot/bin
-rwxr-xr-x 1 xbmc xbmc 615 Dec 15 21:44 /home/xbmc/run.sh
-rwxr-xr-x 1 root root 552 Dec 15 18:56 /usr/share/filebot/bin/filebot.sh

Change the current working directory.

IF filebot.sh is the no-such-file, I suggest you to try with this:
chmod -R a+x /usr/share/filebot/bin/filebot.sh
IF it is your run.sh,
chmod -R a+x /home/xbmc/run.sh
You can try running filebot.sh as the owner. I think it worths a shot.
chown YOURUSERNAME /usr/share/filebot/bin/filebot.sh
chmod u+s /usr/share/filebot/bin/filebot.sh

Related

TAR override the contents of the directory

My understanding of tar command that it will override the content of the file if file exist. Otherwise it would keep as existing.
[root#something~]# ls -al /etc/init.d/
total XX
drwxr-xr-x. 2 root root 83 Jun 14 2018 .
drwxr-xr-x. 10 root root 127 Jun 6 2017 ..
-rwxr-xr-x. 1 root root 7293 Jan 2 2018 network
-rw-r--r--. 1 root root 1160 Feb 20 2018 README
[root#something~]# tar tvf /tmp/env_pkg_1.tar
drwxr-xr-x staff 0 2020-05-29 19:42 etc/
drwxr-xr-x user/staff 0 2020-05-29 18:04 etc/init.d/
-rw-r--r-- user/staff 3383 2020-05-29 18:04 etc/init.d/sshd
[root#something~]# cd /
[root#something /]# tar xf /tmp/env_pkg_1.tar
[root#something/]# ls -al /etc/init.d/
total 16
drwxr-xr-x 2 XXXXXX XXXXXX 18 May 29 18:04 .
drwxr-xr-x. 85 XXXXXX XXXXXX 8192 May 29 19:42 ..
-rw-r--r-- 1 XXXXXX XXXXXX 3383 May 29 18:04 sshd
I am not understand why tar is replacing the entire contents of /etc/init.d
Any inputs would be helpful ?
I belive that /etc/init.d is a link to /etc/rc.d/init.d.
When you untarred that file, it overwrote the link with a directory. All of your files are still in /etc/rc.d/init.d.
To fix your situation, remove /etc/init.d, relink it, and add a h to the tar command:
rm -rf /etc/init.d
cd /etc
ln -s ./rc.d/init.d
cd /
tar xhf /tmp/env_pkg_1.tar
You can use -k or --keep-old-files, so it does not touch any files that are already within the destination. Judging by your output in /etc/init.d/ you want to keep network and README and next to them extract sshd, so in your case, they do not overlap.
Alternatively --keep-newer-files will have tar replace files that are newer from the tar archive, than what's on the destination..

chmod will not work on entries of a directory

How come on this folder
sudo ls -l /etc/letsencrypt/archive/jenkinsv2.sfucsss.org/
total 20
-rw-r--rwx 1 root root 1927 Oct 17 22:58 cert1.pem
-rw-r--rwx 1 root root 1647 Oct 17 22:58 chain1.pem
-rw-r--rwx 1 root root 3574 Oct 17 22:58 fullchain1.pem
-rw----rwx 1 root root 1675 Oct 19 21:15 privkey-rsa.pem
-rw----rwx 1 root root 1704 Oct 17 22:58 privkey1.pem
Doing sudo chmod -R o-rwx /etc/letsencrypt/archive/jenkinsv2.sfucsss.org/ work but doing
sudo chmod -R o-rwx /etc/letsencrypt/archive/jenkinsv2.sfucsss.org/*
chmod: cannot access '/etc/letsencrypt/archive/jenkinsv2.sfucsss.org/*': No such file or directory
Does not?

How to run parametrized bash scripts in Docker CLI

I have an issue that I'm not able to solve. I want to run a bash script that is inside my Docker CLI container, and I want to execute it, passing parameters. Usually, I run scripts using a notation like this:
docker exec -i $CLI_ID bash "./script.sh"
But I don't know how to pass parameters to the script. I tried to execute it with:
docker exec -i $CLI_ID bash "./script.sh PARAM"
But it doesn't work. How can I do it?
Thanks
Try with bash -c option
docker exec -i $CLI_ID bash -c "./script.sh PARAM"
Hope this helps.
Make sure the script is executable , then you dont need the bash and double quotes etc. Just run it striaght away by path/name and provide the options.
[root#ap-p1m-ff ~]# docker exec -i 0c cat /tmp/test.sh
#!bin/bash
ls $1
[root#ap-p1m-ff ~]# docker exec -i 0c /tmp/test.sh -l
total 4
-rw-r--r-- 1 root root 159 Jun 4 18:32 RELEASE
drwxr-xr-x 2 root root 120 Jun 4 18:33 assets
drwxr-xr-x 1 root root 31 Jun 4 18:33 bin
drwxr-xr-x 2 root root 6 Apr 12 2016 boot
drwxr-xr-x 5 root root 340 Jun 7 19:50 dev
drwxr-xr-x 1 root root 22 Jun 7 19:50 etc
but if the script is not already executble the bash should work as well:
[root#ap-p1m-ff ~]# docker exec -i 0c bash /tmp/test.sh -l
total 4
-rw-r--r-- 1 root root 159 Jun 4 18:32 RELEASE
drwxr-xr-x 2 root root 120 Jun 4 18:33 assets
drwxr-xr-x 1 root root 31 Jun 4 18:33 bin
drwxr-xr-x 2 root root 6 Apr 12 2016 boot
drwxr-xr-x 5 root root 340 Jun 7 19:50 dev
drwxr-xr-x 1 root root 22 Jun 7 19:50 etc
drwxr-xr-x 2 root root 6 Apr 12 2016 home
drwxr-xr-x 1 root root 45 Sep 13 2015 lib
drwxr-xr-x 2 root root 34 May 15 14:22 lib64
drwxr-xr-x 2 root root 6 May 15 14:22 media
Add your parameter as a separate argument rather than as part of the filename:
docker exec -i "$CLI_ID" bash "./script.sh" PARAM
This way, you don't have to add another level of escaping to the parameter.

chown: /usr/local: Operation not permitted - issue with brew update /usr/local is not writable - MacOS 10.13.1 high sierra

I am unable to do brew update because I can’t chown /usr/local:
$ brew update
Error: /usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
sudo chown -R $(whoami) /usr/local
based on this: https://github.com/Homebrew/brew/issues/385
I tried these 2 chown command but it didnt work:
$ sudo chown -R $(whoami) $(brew --prefix)
chown: /usr/local: Operation not permitted
$ sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted
Here is my /usr/local listing:
$ cd /usr/local
$ ls -al
total 56
drwxr-xr-x 23 root wheel 736 Dec 2 15:24 .
drwxr-xr-x# 9 root wheel 288 Oct 26 00:22 ..
-rw-r--r-- 1 megasap wheel 0 Dec 2 15:11 .com.apple.installer.keep
drwxr-xr-x 16 megasap admin 512 Jan 11 14:08 .git
drwxr-xr-x 5 megasap admin 160 Dec 2 15:24 .github
-rw-r--r-- 1 megasap admin 1112 Aug 11 2016 .gitignore
-rw-r--r-- 1 megasap admin 253 Aug 11 2016 .travis.yml
-rw-r--r-- 1 megasap admin 291 Aug 11 2016 .yardopts
-rw-r--r-- 1 megasap admin 3161 Aug 11 2016 CODEOFCONDUCT.md
drwxr-xr-x 35 megasap admin 1120 Jan 11 11:35 Cellar
-rw-r--r-- 1 megasap admin 1241 Jan 26 2016 LICENSE.txt
drwxr-xr-x 9 megasap admin 288 Dec 2 15:25 Library
-rw-r--r-- 1 megasap admin 5451 Aug 11 2016 README.md
drwxr-xr-x 262 megasap admin 8384 Jan 11 23:09 bin
drwxr-xr-x 11 megasap admin 352 Dec 2 15:25 etc
drwxr-xr-x 57 megasap staff 1824 Dec 2 15:25 include
drwxr-xr-x 102 megasap staff 3264 Dec 2 15:25 lib
drwx------ 4 megasap wheel 128 Dec 2 15:24 libexec
drwxr-xr-x 3 megasap admin 96 Dec 2 15:23 n
drwxr-xr-x 34 megasap admin 1088 Dec 2 15:25 opt
drwxr-xr-x 8 megasap admin 256 Dec 2 15:24 sbin
drwxr-xr-x 16 megasap admin 512 Dec 2 15:25 share
drwxr-xr-x 8 megasap admin 256 Dec 2 15:25 var
I'm using macOS 10.13.1 high sierra.
Reinstalling Homebrew worked for me
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
You may want to try:
sudo chown -R $(whoami) $(brew --prefix)/*
For more see: https://github.com/Homebrew/brew/issues/3228
Apparently this is due to mac's "system integrity configuration". To get around this you need to reboot your machine into recovery mode (restart your machine and hold down ⌘+R) go into Utilities > Terminal and type the command:
csrutil disable
reboot
And then run your chown command. I guess its recommended to reenable this after changing permissions to re-enable the security.
Full disclosure, I haven't tried this myself - I'll give it a go later today since its a massive PITA. For the record, I'm only attempting to install python3.
Original information
On Mac, I have to give "Full Disk Access" to the terminal using the below page -
https://macreports.com/terminal-says-operation-not-permitted-on-mac-fix/
uninstall and install Homebrew using https://github.com/Homebrew/install

combine cp / chmod to modify perms during cp

I was looking for a way to cp a file and mod its perms to 400 at the same time... after some testing in the public_html folder...
public_html >> ls -lah
-rw-r--r-- 1 user user 0 Feb 27 14:21 a.txt
public_html >> cp a.txt{,.bak}
-rw-r--r-- 1 user user 0 Feb 27 14:21 a.txt
-rw-r--r-- 1 root root 0 Feb 27 14:23 a.txt.bak
perms are still the same (644) and although the file is owned by root, it is still readable via public_html
public_html >> cp a.txt{,.bak} && chmod 400 a.txt.bak
-rw-r--r-- 1 user user 653 Feb 27 14:26 a.txt
-r-------- 1 root root 653 Feb 27 14:30 a.txt.bak
this works but looking for something for a set newbs to use
awk/sed command possibly?
dont think I'm missing a cp flag that could modify the perms, wasn't seeing anything and don't think there are but wanted to pick the collective brain
thanks...
install(1) can both copy files and create directories, and set their permissions at the same time.
install -m 0400 foo bar/

Resources