Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Batch to create semaphore

Posted on 2013-11-13
2
Medium Priority
?
603 Views
Last Modified: 2013-12-03
After receiving a FILENAME_yyyymmdd .txt file from vendor I need a Unix batch script to accomplish the following:
1.      Copy the original file to the "archive"
2.      Rename original incoming file FILENAME_yyyymmdd .txt to FILENAME.txt
3.      FILENAME.sem - create a semaphore file. Nothing needs to be in here. It is
                 simply a flag to the batch that indicates the file retrieval is complete.
4.              Alert relevant parties via email
The most important pieces of that are created the .sem file and transferring/renaming the FILENAME_yyyymmdd .txt  to FILENAME.txt file.
0
Comment
Question by:lsbrown1
  • 2
2 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 39648267
#Assuming that $filename is FILENAME_yyyymmdd.txt
cp $filename /path/archive/
#Strip off _ and everything past _
temp=$(echo $filename | sed 's/\(.*\)_.*/\1/')

#move
mv $filename $temp.txt
#create blank file
echo > $temp.sem
0
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 2000 total points
ID: 39648356
Note that the above will only strip the last _ and everything following it, so filename can have _ characters and it will still work. If you want to strip the first _ and everything after, you could use something a lot simpler like:
temp=$(echo $filename | sed 's/_.*//')
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Make the most of your online learning experience.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question