Solved

Batch to create semaphore

Posted on 2013-11-13
2
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.:
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

628 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