Solved

Batch to create semaphore

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now