Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:07:25+00:00 2026-05-27T20:07:25+00:00

I need to write a shell script to run as a cron task, or

  • 0

I need to write a shell script to run as a cron task, or preferably on creation of a file in a certain folder.

I have an incoming and an outgoing folder (they will be used to log mail). There will be files created with codes as follows…

bmo-001-012-dfd-11 for outgoing and 012-dfd-003-11 for incoming. I need to filter the project/client code (012-dfd) and then place it in a folder in the specific project folder.

Project folders are located in /projects and follow the format 012-dfd. I need to create symbolic links inside the incoming or outgoing folders of the projects, that leads to the correct file in the general incoming and outgoing folders.

/incoming/012-dfd-003-11.pdf -> /projects/012-dfd/incoming/012-dfd-003-11.pdf
/outgoing/bmo-001-012-dfd-11.pdf -> /projects/012-dfd/outgoing/bmo-001-012-dfd-11.pdf

So my questions

  1. How would I make my script run when a file is added to either incoming or outgoing folder
    1. Additionally, is there any associated disadvantages with running upon file modification compared with running as cron task every 5 mins
  2. How would I get the filename of recent (since script last run) files
  3. How would I extract the code from the filename
  4. How would I use the code to create a symlink in the desired folder

EDIT: What I ended up doing…

while inotifywait outgoing; do find -L . -type l -delete; ls outgoing | php -R '
if(
    preg_match("/^\w{3}-\d{3}-(\d{3}-\w{3})-\d{2}(.+)$/", $argn, $m)
    && $m[1] && (file_exists("projects/$m[1]/outgoing/$argn") != TRUE)
){
    `ln -s $(pwd)/outgoing/$argn projects/$m[1]/outgoing/$argn;`;
}
'; done;

This works quite well – cleaning up deleted symlinks also (with find -L . -type l -delete) but I would prefer to do it without the overhead of calling php. I just don’t know bash well enough yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:07:26+00:00Added an answer on May 27, 2026 at 8:07 pm

    Some near-answers for your task breakdown:

    1. On linux, use inotify, possibly through one of its command-line tools, or script language bindings.
    2. See above
    3. Assuming the project name can be extracted thinking positionally from your examples (meaning not only does the project name follows a strict 7-character format, but what precedes it in the outgoing file also does):

      echo `basename /incoming/012-dfd-003-11.pdf` | cut -c 1-7
      012-dfd
      echo `basename /outgoing/bmo-001-012-dfd-11.pdf`| cut -c 9-15
      012-dfd
      
      • mkdir -p /projects/$i/incoming/ creates directory /projects/012-dfd/incoming/ if i = 012-dfd,
      • ln -s /incoming/foo /projects/$i/incoming/foo creates a symbolic link from the latter argument, to the preexisting, former file /incoming/foo.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a shell script to be scheduled to run daily to
I need to write a Shell Script to process a huge folder of nearly
I need to write a python script that launches a shell script and import
I need help to write a shell script to calculate the directory space in
I am trying to do the following task: write a shell script called changedir
I need to write a shell script that pick all the files (not directories)
I need to write a shell script where I read a variable from environment.
I want to write a shell script wherein I have to find out the
I am new to this shell-script programming so need your help to write a
I need to write a program used internally where different users will have different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.