<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Scripting issue. in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990474#M100347</link>
    <description>Thanks for the ideas.!!</description>
    <pubDate>Thu, 13 Jul 2006 14:15:21 GMT</pubDate>
    <dc:creator>rmueller58</dc:creator>
    <dc:date>2006-07-13T14:15:21Z</dc:date>
    <item>
      <title>Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990464#M100337</link>
      <description>I have a situation which requires checking for an existing file name in a directory then I need to copy a file with a new document ID &lt;BR /&gt;&lt;BR /&gt;the format of the file name is fairly simplistic. &lt;BR /&gt;&lt;BR /&gt;&lt;DISTID&gt;_&lt;APPID&gt;_&lt;DOCID&gt;.ext &lt;BR /&gt;&lt;BR /&gt;the customer puts file in a staging area, I have a destination folder &lt;BR /&gt;&lt;BR /&gt;What I've done is defined some variables and am trying to parse into the file name to see the DOCID in the destination folder exists compared to the staged files, and if it exists then I want to increment the DOCID by one during the cp. &lt;BR /&gt;&lt;BR /&gt;my script thus far is fairly simplistic, I have to get it running in cron so I don't have to baby sit a user process.. &lt;BR /&gt;&lt;BR /&gt;I have a CASE statement that looks at the file name and pulls the DISTID so I can apply the correct destination folder. &lt;BR /&gt;#!/bin/bash &lt;BR /&gt;export p1=/upload_resumes/rextest/&lt;BR /&gt;export p2=/upload_resumes/backup/&lt;BR /&gt;export p3=/mps-docs/mps-docs/app-staging/rextest/&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for fn in `ls /mps-docs/mps-docs/app-staging/`&lt;BR /&gt;do&lt;BR /&gt;for dist in `echo $fn |awk '{print substr($1,1,3)}'`&lt;BR /&gt;# DISTRICT SPECIFIC INFORMATION&lt;BR /&gt;do&lt;BR /&gt;export dist&lt;BR /&gt;&lt;BR /&gt;case $dist in&lt;BR /&gt;wst)&lt;BR /&gt;export distpath="$wst"&lt;BR /&gt;;;&lt;BR /&gt;mps)&lt;BR /&gt;export distpath="$mps"&lt;BR /&gt;;;&lt;BR /&gt;esu)&lt;BR /&gt;export distpath="$esu"&lt;BR /&gt;;;&lt;BR /&gt;plv)&lt;BR /&gt;export distpath="$plv"&lt;BR /&gt;;;&lt;BR /&gt;ral)&lt;BR /&gt;export distpath="$ral"&lt;BR /&gt;;;&lt;BR /&gt;*)&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;Then i need to look at the file name again to pull our the DOCID  and check the DOCID against the destination folder. The customer has thus far given the APPID of NEW or ADD, which makes the cp a bit more problematic. &lt;BR /&gt;&lt;BR /&gt;the file name generally will look like this. &lt;BR /&gt;&lt;BR /&gt;mpsplus_1234_1.pdf or mpsplus_1234_2.pdf the _2.pdf can be as many as _99.pdf &lt;BR /&gt;&lt;BR /&gt;I am drawing a blank on my scripting brain for some reason today. &lt;BR /&gt;&lt;BR /&gt;Any scripting guys with some ideas I'd appreciate it. &lt;BR /&gt;&lt;BR /&gt;Rex Mueller&lt;/DOCID&gt;&lt;/APPID&gt;&lt;/DISTID&gt;</description>
      <pubDate>Wed, 12 Jul 2006 11:16:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990464#M100337</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-12T11:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990465#M100338</link>
      <description>Hi Rex:&lt;BR /&gt;&lt;BR /&gt;Give a file name in the variable FILE:&lt;BR /&gt;&lt;BR /&gt;[ -f "${FILE}" ] &amp;amp;&amp;amp; echo "exists" || echo "does not exist" &lt;BR /&gt;&lt;BR /&gt;...will print "exists" or "does not exist"&lt;BR /&gt;&lt;BR /&gt;See the manpages for 'test(1)'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 12 Jul 2006 11:36:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990465#M100338</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-07-12T11:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990466#M100339</link>
      <description>replace everything from your first for loop with the following:&lt;BR /&gt;&lt;BR /&gt;for fn in /mps-docs/mps/docs/app-staging/*&lt;BR /&gt;do&lt;BR /&gt;__echo $fn | cut -d. -f1 | &lt;BR /&gt;____IFS=_ read distID appID docID&lt;BR /&gt;__echo $fn | cut -d. -f2 | read ext&lt;BR /&gt;&lt;BR /&gt;__eval distpath="$dist"&lt;BR /&gt;__if [[ -z $distpath ]]; then&lt;BR /&gt;____print "ERROR: invalid distID $distID"&lt;BR /&gt;____exit 1&lt;BR /&gt;__fi&lt;BR /&gt;&lt;BR /&gt;__while [[ -f ${distpath}/${distID}_${appID}_${docID}.${ext} ]]&lt;BR /&gt;__do&lt;BR /&gt;____(( docID += 1 ))&lt;BR /&gt;____if (( docID &amp;gt; 99 )); then&lt;BR /&gt;______print "ERROR: docID too high!"&lt;BR /&gt;______exit 2&lt;BR /&gt;____fi&lt;BR /&gt;__done&lt;BR /&gt;&lt;BR /&gt;__mv $fn ${distpath}/${distID}_${appID}_${docID}.${ext}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;you may want to add some echo statements to see that your variables are set correctly, and you may want to do "typeset -Z2 docID" to make sure you always have a 2 digit docID (it adds the leading zero for #&amp;lt;10).&lt;BR /&gt;&lt;BR /&gt;the eval statement saves you from your big case statement, and the following if validates that the env var for the distID was set.</description>
      <pubDate>Wed, 12 Jul 2006 11:49:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990466#M100339</guid>
      <dc:creator>Greg Vaidman</dc:creator>
      <dc:date>2006-07-12T11:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990467#M100340</link>
      <description>sorry, the eval line should read&lt;BR /&gt;eval distpath="\${$dist}"&lt;BR /&gt;&lt;BR /&gt;the leading "_" on each line are to simulate spaces, so you the forum doesn't mess up the indentation of the script</description>
      <pubDate>Wed, 12 Jul 2006 11:52:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990467#M100340</guid>
      <dc:creator>Greg Vaidman</dc:creator>
      <dc:date>2006-07-12T11:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990468#M100341</link>
      <description>Hi Greg:&lt;BR /&gt;&lt;BR /&gt;You can (recently) chekc the "Retain Format" box at the bottom of your post to cause leading spaces to be retained for formatting scripts.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 12 Jul 2006 12:06:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990468#M100341</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-07-12T12:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990469#M100342</link>
      <description>Thanks guys, let me take a look.. &lt;BR /&gt;&lt;BR /&gt;greg's idea looks like it will probably do the trick but I was having a major brain drain this morning. &lt;BR /&gt;&lt;BR /&gt;Cold Wendy's fries don't help matters either. :( &lt;BR /&gt;</description>
      <pubDate>Wed, 12 Jul 2006 12:11:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990469#M100342</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-12T12:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990470#M100343</link>
      <description>I've been using echos instead of cp's in my testing stuff..  &lt;BR /&gt;</description>
      <pubDate>Wed, 12 Jul 2006 12:13:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990470#M100343</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-12T12:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990471#M100344</link>
      <description>what shells does IFS work with? I am using a bash shell.. &lt;BR /&gt;&lt;BR /&gt;here is what I am trying, &lt;BR /&gt;&lt;BR /&gt;I am defining some of the more static variables first such as &lt;BR /&gt;&lt;BR /&gt;export SOURCEDIR="/mps-docs/mps-docs/app-staging/"  &lt;BR /&gt;export DESTDIR="/web-folder/"&lt;BR /&gt;&lt;BR /&gt;This script is driven by one of my school districts, hence the district ID.. &lt;BR /&gt;&lt;BR /&gt;I define the distid in a case statement. the dbname is &lt;DIST&gt;plus so for example mpsplus is for mps district.  that is simple enough.. As I only have the potential of 11 potential districts the case is a small piece of the pie. &lt;BR /&gt;&lt;BR /&gt;the basic concern is &lt;BR /&gt;moving files from a static directory to another static directory, but looking at the APPID and DOCID. &lt;BR /&gt;&lt;BR /&gt;IF THE APPID ID exists in the DESTINATION FOLDER, with a specific DOCID then increment the DOCID + 1 and retain the extension. &lt;BR /&gt;&lt;BR /&gt;It looks as though if I define the FILENAME first, then parse for the sub variables within the document name and increment the DOCID with portions from you guys I can probably get it to work. &lt;BR /&gt;&lt;BR /&gt;I will muck with it today, and see if I can get it running. Thanks again. &lt;BR /&gt;&lt;/DIST&gt;</description>
      <pubDate>Thu, 13 Jul 2006 08:36:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990471#M100344</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-13T08:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990472#M100345</link>
      <description>I ran through it once with greg's script, and it put a file in my destination folders with _&lt;DOCID&gt;. it didn't pass the IFS information (or maybe the IFS portion isn't reading the filename correctly.&lt;/DOCID&gt;</description>
      <pubDate>Thu, 13 Jul 2006 09:27:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990472#M100345</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-13T09:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990473#M100346</link>
      <description>Guys this is what  I came up with, and it seems to be working.. Thanks much for the muse time. &lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;export distpath=/upload_resumes/rextest/&lt;BR /&gt;export source=/mps-docs/mps-docs/app-staging/rextest/&lt;BR /&gt;&lt;BR /&gt;cd $source &lt;BR /&gt;for fn in `ls`&lt;BR /&gt;do&lt;BR /&gt;echo $fn&lt;BR /&gt;echo $distpath &lt;BR /&gt;export distID=`echo $fn |awk -F_ '{print $1}'`&lt;BR /&gt;export appID=`echo $fn |awk -F_ '{print $2}'` &lt;BR /&gt;export docID=`echo $fn |awk -F_ '{print $3}'|cut -d. -f1` &lt;BR /&gt;export ext=`echo $fn |awk -F_ '{print $3}'|cut -d. -f2` &lt;BR /&gt;echo $fn |cut -d. -f2 | read ext&lt;BR /&gt;&lt;BR /&gt;echo $distID &lt;BR /&gt;echo $appID &lt;BR /&gt;echo $docID &lt;BR /&gt;echo $ext &lt;BR /&gt;read&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [[ -z $distpath ]]; then&lt;BR /&gt;echo "ERROR: invalid distID $distID"&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;while [[ -f ${distpath}/${distID}_${appID}_${docID}.${ext} ]]&lt;BR /&gt;do&lt;BR /&gt;(( docID += 1 ))&lt;BR /&gt;if (( docID &amp;gt; 99 )); then&lt;BR /&gt;echo "ERROR: docID too high!"&lt;BR /&gt;exit 2&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;cp $fn ${distpath}mpsplus_${appID}_${docID}.${ext}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jul 2006 13:29:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990473#M100346</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-13T13:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990474#M100347</link>
      <description>Thanks for the ideas.!!</description>
      <pubDate>Thu, 13 Jul 2006 14:15:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-issue/m-p/4990474#M100347</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-07-13T14:15:21Z</dc:date>
    </item>
  </channel>
</rss>

