Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. I'm having a bizarre-ass #Bash #scripting problem.

I'm having a bizarre-ass #Bash #scripting problem.

Scheduled Pinned Locked Moved Uncategorized
bashscriptinglinuxhelpbashscript
5 Posts 2 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kagan@wandering.shopK This user is from outside of this forum
    kagan@wandering.shopK This user is from outside of this forum
    kagan@wandering.shop
    wrote last edited by
    #1

    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

    #LinuxHelp #BashScript

    kagan@wandering.shopK 1 Reply Last reply
    1
    0
    • kagan@wandering.shopK kagan@wandering.shop

      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

      #LinuxHelp #BashScript

      kagan@wandering.shopK This user is from outside of this forum
      kagan@wandering.shopK This user is from outside of this forum
      kagan@wandering.shop
      wrote last edited by
      #2

      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

      kagan@wandering.shopK 1 Reply Last reply
      0
      • kagan@wandering.shopK kagan@wandering.shop

        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

        kagan@wandering.shopK This user is from outside of this forum
        kagan@wandering.shopK This user is from outside of this forum
        kagan@wandering.shop
        wrote last edited by
        #3

        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

        kagan@wandering.shopK 1 Reply Last reply
        0
        • kagan@wandering.shopK kagan@wandering.shop

          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

          kagan@wandering.shopK This user is from outside of this forum
          kagan@wandering.shopK This user is from outside of this forum
          kagan@wandering.shop
          wrote last edited by
          #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

          surefire@infosec.exchangeS 1 Reply Last reply
          0
          • kagan@wandering.shopK kagan@wandering.shop

            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

            surefire@infosec.exchangeS This user is from outside of this forum
            surefire@infosec.exchangeS This user is from outside of this forum
            surefire@infosec.exchange
            wrote last edited by
            #5

            @kagan Without seeing the script itself, two thoughts:

            1. Make sure the script starts with a #! line, since that tells the OS what kind of script it is.

            2. 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)
            ...
            1 Reply Last reply
            0
            • R relay@relay.infosec.exchange shared this topic
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups