I'm having a bizarre-ass #Bash #scripting problem.
-
I'm having a bizarre-ass #Bash #scripting problem. I'm at my wits' end.
I have a script that scans a directory and picks a random file from it. This script works just fine if I invoke it manually, from the command line in a terminal window.
But if I run it from the Linux Mint/Cinnamon menu (start menu, whatever), it hangs when it tries to list the files in the dir. Likewise when run from crontab (which is how I really want to run it most of the time). 🧵 1/4
-
I'm having a bizarre-ass #Bash #scripting problem. I'm at my wits' end.
I have a script that scans a directory and picks a random file from it. This script works just fine if I invoke it manually, from the command line in a terminal window.
But if I run it from the Linux Mint/Cinnamon menu (start menu, whatever), it hangs when it tries to list the files in the dir. Likewise when run from crontab (which is how I really want to run it most of the time). 🧵 1/4
I've set it up to do some logging. Among other things, I've had it check with the -d and -r flags that yes, the target directory exists, and is readable by the script. (It's writable for it, as well; I've even had the script touch a zero-byte file in there. That works fine, both from the menu and via cron.) 2/4
-
I've set it up to do some logging. Among other things, I've had it check with the -d and -r flags that yes, the target directory exists, and is readable by the script. (It's writable for it, as well; I've even had the script touch a zero-byte file in there. That works fine, both from the menu and via cron.) 2/4
But when I have it run files=($dirname/*) (with "shopt -s nullglob" set, although I know the directory in question is populated)... it hangs. Nothing more goes into the log, and the script doesn't terminate. I have to Ctrl-C it.
Unless I run it manually! Then it works fine! So it's not a permissions issue, or a syntax issue! (Also, when it creates that zero-byte file, it shows up with my user and group ownership. So it's doubly not a permissions issue.) 3/4
-
But when I have it run files=($dirname/*) (with "shopt -s nullglob" set, although I know the directory in question is populated)... it hangs. Nothing more goes into the log, and the script doesn't terminate. I have to Ctrl-C it.
Unless I run it manually! Then it works fine! So it's not a permissions issue, or a syntax issue! (Also, when it creates that zero-byte file, it shows up with my user and group ownership. So it's doubly not a permissions issue.) 3/4
Just in case, there are no spaces or weird characters anywhere in the directory path or any of the filenames. The weirdest anything gets is a dash/hyphen. Full pathnames are are along the lines of /home/kagan/Pictures/foo-1234.jpg and suchlike, plus one file that has underscores.
And again, it works fine when I run it from the command line, so I don't understand why it fails from the menu or crontab. I've tried everything I can think of. Has anyone got any ideas? Thank you. Boosts welcome. 4/4
-
Just in case, there are no spaces or weird characters anywhere in the directory path or any of the filenames. The weirdest anything gets is a dash/hyphen. Full pathnames are are along the lines of /home/kagan/Pictures/foo-1234.jpg and suchlike, plus one file that has underscores.
And again, it works fine when I run it from the command line, so I don't understand why it fails from the menu or crontab. I've tried everything I can think of. Has anyone got any ideas? Thank you. Boosts welcome. 4/4
@kagan Without seeing the script itself, two thoughts:
Make sure the script starts with a #! line, since that tells the OS what kind of script it is.
Since you mentioned being able to touch a file, write to a log file to see exactly where it is hanging:
#!/bin/bash
echo 0 >> mylogfile
(first line of code here)
echo 1 >> mylogfile
(second line of code here)
echo 2 >> mylogfile
(third line of code here)
... -
R relay@relay.infosec.exchange shared this topic