LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-11-2020, 12:03 PM   #1
arckane
Member
 
Registered: Sep 2005
Location: UK
Distribution: Gentoo/Debian/Ubuntu
Posts: 308

Rep: Reputation: 39
Incron misbehaving with file name expansion


Hi folks, it's been awhile!

I use incrontab to call a script to process files as they are uploaded to my server. The line looks like this:

/srv/dirwatched/ IN_CLOSE_WRITE,IN_MOVED_TO /bin/bash /srv/scripts/encode.sh $#

Simple stuff, and simple we love. Now, if someone uploads a file with an apostrophe it isn't processed. Fine, I'll wrap $# in double quotes... "$#" won't process the files properly, it's as if the script doesn't like the way the file name is presented.


Ideas?
 
Old 06-11-2020, 04:54 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,686

Rep: Reputation: Disabled
I think you're quoting it in the wrong place. It should be quoted inside /srv/scripts/encode.sh, not in the incrontab.

Perl module String::ShellQuote provides a command, shell-quote, that may help you quote arbitrary filenames inside the script. The package name is libstring-shellquote-perl in Debian-based distros, perl-String-ShellQuote in most RPM-based distros, perl-string-shellquote in Arch.

Last edited by shruggy; 06-12-2020 at 05:43 AM.
 
Old 06-11-2020, 10:16 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,793

Rep: Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952
As a frame of reference incron on CentOS 7 works as expected but just a limited test since we don't know how your upload process works.

Code:
/home/user/mydir	IN_CREATE,IN_CLOSE_WRITE  /home/user/myscript.sh "$#" 

#!/bin/bash

echo "$@" >> /home/user/data.dat
incron and my script was tested using the touch command.
touch ~/mydir/"test'a.txt"

And as expected data.dat contains

test'a.txt
test'a.txt

I assume your uploaded process works as expected so is it due to incron not passing the file name correctly or something else wrong with your encode script?
 
  


Reply

Tags
incron, incrond, incrontab



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to run commands on File or Directory changes with Incron on Ubuntu LXer Syndicated Linux News 0 04-12-2016 04:15 PM
LXer: How to trigger commands on File/Directory changes with Incron on Debian LXer Syndicated Linux News 0 09-24-2015 05:50 PM
variable expansion and pathname expansion ShadeLover Linux - General 6 04-22-2015 10:56 PM
LXer: Incron – a cron based on File System events LXer Syndicated Linux News 0 02-28-2011 12:50 AM
LXer: Triggering Commands On File/Directory Changes With Incron LXer Syndicated Linux News 0 09-02-2008 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration