Solved

Batch to create semaphore

Posted on 2013-11-13
2
561 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 500 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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

821 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