You are not logged in.
I have tested now several versions
Version 1
head central_sync
#!/bin/bash
# synchronise Unlimited number of directories on different hosts
...
central_sync is a hardlink to /usr/local/bin/central_sync.bash
version 2
cat central_sync2
#!/bin/sh
set
/bin/bash /usr/local/bin/central_sync.bash
exit 0
version 3
cat central_sync3
#!/bin/sh
set
/bin/bash -x /usr/local/bin/central_sync.bash
exit 0
version 4
cat central_sync4
#!/bin/sh
set
/bin/bash --posix /usr/local/bin/central_sync.bash
exit 0
They all produce in the protocol log:
...
set
...
SHELL=/bin/sh
Consequently the program fails, which runs when called in the console/terminal
Parameter expansion fails in the rsync command
Last edited by bai4Iej2need (2024-10-28 10:44:29)
The devil, you know, is better than the angel, you don't know. by a British Citizen, I don't know too good.
One generation abandons the enterprises of another like stranded vessels. By Henry David Thoreau, WALDEN, Economy. Line 236 (Gutenberg text Version)
broken by design :
https://bugs.debian.org/cgi-bin/bugrepo … bug=958390
Offline
I'm confused... perhaps because I don't know what "the protocol log" is or may be because you do not say if the log is produced when /etc/cron.hourly/somejob runs or when you start central_sync.bash manually
If I remember this correctly, cron does not know the environment you use in the terminal. That may explain the difference you observe, and possibly the parameter expansion problem.
Prove to yourself that /etc/cron.hourly/somejob is executable and that cron actually starts it. Study the output from set. Move on to locate what fails in /etc/cron.hourly/somejob
--
OddS
Last edited by OddS (2024-10-19 09:30:19)
Offline
Hi
I failed to explain that I have a protocol function in the script which writes to /var/log/somejob/somejob.log, if executed as root.
I verified now that the script starts indeed as a dash script instead of starting as bash. Some command inside requires a bashism and then the script fails.
Works as root !
I correct now the headline as well.
Last edited by bai4Iej2need (2024-10-28 11:20:23)
The devil, you know, is better than the angel, you don't know. by a British Citizen, I don't know too good.
One generation abandons the enterprises of another like stranded vessels. By Henry David Thoreau, WALDEN, Economy. Line 236 (Gutenberg text Version)
broken by design :
https://bugs.debian.org/cgi-bin/bugrepo … bug=958390
Offline
It is not possible to set the shell for a particular task in /etc/cron.hourly, etc/cron.daily, etc/cron.weekly and /etc/cron.monthly.
Setting shell for all jobs is in /etc/default/cron.
I moved the job into the crontab (crontab -e) of root.
Now we go to the next problem.
The devil, you know, is better than the angel, you don't know. by a British Citizen, I don't know too good.
One generation abandons the enterprises of another like stranded vessels. By Henry David Thoreau, WALDEN, Economy. Line 236 (Gutenberg text Version)
broken by design :
https://bugs.debian.org/cgi-bin/bugrepo … bug=958390
Offline
If your working environment relies heavily on bash, you might consider replacing DASH with BASH as the default shell as I did. It "just works" and I've had no cause to reconsider the decision :
HOWTO : use bash instead of dash as the default shell in daedalus
https://dev1galaxy.org/viewtopic.php?id=5753
Cheers,
--K
Offline
another option is to use an inline script as a function with a heredoc.
here's an example of what is a posix compliant shell script that wraps the program nsxiv to add functionality but since there's no good way to decode a uri to a path with just the core utils a simple python script is used from a function, this sort of thing can be done with any interpreter for any language, say you want an awk script or a perl script, even a bash script the process would be all the same.
#!/bin/sh
TMPDIR="${TMPDIR:-/tmp}"
tmp="$TMPDIR/nsxiv_rifle_$$"
is_img_extension() {
grep -iE '\.(jpe?g|png|gif|svg|jxl|webp|tiff|heif|avif|ico|bmp|pam|pbm|ppm|tga|qoi|ff|jpg_large)$'
}
listfiles() {
if [ -n "$SORT_BY_TIME" ]; then
find -L "$1" -maxdepth 1 -type f -printf '%T@\t%p\n' |
sort -n | cut -f2 | is_img_extension | tee "$tmp"
else
find -L "$1" -maxdepth 1 -type f -print |
is_img_extension | sort -Vfd | tee "$tmp"
fi
}
open_img() {
file="$1"; shift;
# only go through listfiles() if the file has a valid img extension
if echo "$file" | is_img_extension >/dev/null 2>&1; then
trap 'rm -f $tmp' EXIT
count="$(listfiles "///${file%/*}" | grep -nF "$file")"
fi
if [ -n "$count" ]; then
nsxiv-env -i -n "${count%%:*}" "$@" -- < "$tmp"
else
# fallback incase file didn't have a valid extension, or we couldn't
# find it inside the list
nsxiv-env "$@" -- "$file"
fi
}
uri2path() {
python3 - "$@" <<'___HEREDOC'
from urllib.parse import unquote, urlparse
from sys import argv
for arg in argv[1:]:
print(unquote(urlparse(arg).path))
___HEREDOC
}
[ "$1" = '--' ] && shift
case "$1" in
"") echo "Usage: ${0##*/} PICTURES" >&2; exit 1 ;;
/*) open_img "$1" ;;
"~"/*) open_img "$HOME/${1#"~"/}" ;;
file:///*) open_img "$(uri2path "$1")" ;;
trash:///*)
trash_dir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash/files"
open_img "${trash_dir}$(uri2path "$1")" -N "nsxiv_trash"
;;
*) open_img "$PWD/$1" ;;
esac
another option is to have sub-scripts that may live in library paths, something like /usr/local/lib/mycronscript/module and then you run that module from inside your script as another executable.
Offline