Shell script help required

hi
scenario: A folder contains n - number of folder which contains few generated pdf reports.
NOW I need a shell script which will solve two purpose simultaneously:
1. it will create folder for each folders in the specific directory according to the month and year AND it will copy the respected folder within them including the pdf files.
2. The newly created folders will be converted into a tar compressed file.
EXAMPLES:
Say the folder name is E-SEVA wich contains folders say 10_MAR_2011,12_MAR_2011 and n_YthMonth_2011 and same for 2012 year also.Now I need folders rather a tarz file for each month say MARCH_2011,FEB_2011,MARCH_2012,FEB_2012 and so on.
kind regards

The following should do:
months="JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
years="2011 2012"
dir="E-SEVA"
cd "$dir"
for month in $months; do
   for year in $years; do
      for folder in $(find . -type d -name "*_${month}_${year}"); do
         mkdir -p "${month}_${year}"
         cp -pR "$folder" "${month}_${year}/"
         tar -rf "${month}_${year}.tar" "${month}_${year}"
      done
   done
doneNote: You cannot add files to a compressed archive.

Similar Messages

  • Shell Script Help

    I'm an IBM guy and I was assigned this MAC projet. I'm a MAC noob. I have a multi-user eMac. The user account folders are blown away when the computer shuts down leaving just the root accout and default account. I included a new javapolicy file in the default user account. A file called java.policy resides in the user home folder at log in (/users/johndoe/java.policy) for every new user that logs in. I need to create a logon shell script that finds the java.policy file in their home folder and renames it .java.policy to make it hidden. Remaming it in the default profile is not an option, and I don't know who will be using the computer at any given day. Can someone help me with the code.
    #!/bin/bash/
    I'm clueless, thanks for the help

    The generic bash rename syntax for your specified command is:
    mv /Users/shortuser/javapolicy /Users/shortuser/.java.policy
    Here's a typical script:
    #!/bin/bash
    mv /path/to/source/.java.policy /Users/shortuser/.java.policy
    The most direct mechanism would be via a computer login preference and workgroup manager, setting up a script that executes at user login. That script is invoked at login and can copy over or create the required file. Another of the usual techniques for executing commands at login is the so-called [login hook (HT2420)|http://support.apple.com/kb/HT2420], though if you're using Open Directory (OD) or OD with Active Directory (AD), it'll probably be better to go that way than the login hook.
    Other discussions [here|http://arstechnica.com/civis/viewtopic.php?f=20&t=416343] and [here|http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-appl et.html]
    I'd tend to expect to see the policytool used for this file, too. Launch Terminal.app and see +man policytool+ for details on that.
    I'd also tend to expect to see this sort of stuff established within the system-wide policy module from the JRE that's usually located in [the system library directory |http://stackoverflow.com/questions/4372060/java-security-file-location-on-mac- snow-leopard] (/Library/Java/Home/lib/security/java.policy) and not with a per-user setting, too, and that's a rather different approach than populating the per-user settings. (But then I'm not a Java geek.)
    FWIW, it's "Mac" and not "MAC", it's Unix, and files and directories doesn't get blown away unless there's a problem somewhere, or unless this is a school or kiosk or other environment that's using specific system-reset processing. And if there's system-reset processing here, then you'll obviously need to work within that. That processing is usually associated with OD, hence the earlier pointers. (And if there's this sort of reset processing going on, there's usually a reason for it, I'd probably try to keep as much sensitive stuff out of the local directories as I could reasonably manage.)

  • Shell script that required password

    Hi,
    I'm using an automator script to upload some files to a remote Linux server, and I'm using rsync in an automator shell script action.
    That command required a password to work, how can I enter the password in the shell script action?
    Thanks

    Thanks for your answer, but as I'm no expert in AS,
    I'm not sure to understand your answer.
    How do those parameters are sent to AS?
    You put it in the statement:
    do shell script "rsync /source /dest" password "xyzzy" user name "you"
    You can set up a keychain for the password and retrieve it when needed, to be secure in your code. Post back or head over to AS forum, we'll help you out. http://discussions.apple.com/forum.jspa?forumID=724
    I suppose it can be run within Automator using a run
    AS instead of a run shell script. As my automator do
    some other task too.
    Yes, Automator has Run AppleScript action.
    And yes, you're right, iWeb publishing that is! Good
    guest!
    I saw some of your posts in iWeb board.
    I'm mucking around with iWeb, it's a bloated monster. There are quite a few restrictions in iWeb, I had to hand code some of the stuffs, such as meta data keywords, tricky stuffs... I'm thinking of writing a script for post production.

  • Unix shell Script Help

    Hi,
    I am not to familiar with shell scripting. And i need a shell script that would look for a certain filename (eg: ASN*.txt) in a directory(Eg:data) and if it does find that, it calls a concurrent program(Eg: abc.xyz) and once this is called and procedure excutes successfully, I take the file and move it to another directory(Eg:archive)
    Any help would be aprreciated.
    Thanks,
    Ja

    You bet.
    http://steve-parker.org/sh/sh.shtml
    http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Unix/CShellII.html
    and about 300,000 more hits on Google

  • Shell scripts  help

    Hi, I am not experienced in shell scripts, I hope someone can give some hint for the following problem
    I have html file like this
    <html>
    <body>
    Some stuff
    More stuff
    <pre>
    A
    B
    </pre>
    Still more stuff
    And more
    <pre>
    C
    D
    </pre>
    Additional stuff
    </body>
    </html>
    I want to write the script to red this file and dump out
    The items within the <pre> tags. For example, the output for the above file
    shouild be
    A
    B
    C
    D
    Thanks
    Angela

    Hi,
    I have tried to go little far and created a little complicated solution.
    This may be usefull if,
    1) There are more than one <pre></pre> pairs in one line
    2) The <pre> tag can come in mixed case
    3) And you want everything as it is in the <pre> tag
    Means if the f.html file is,
    <body>
    My name is Einstein <pre>HA ha</PRE> and I am trying <PRE> FUNNY </Pre>
    things just for practise. This may be <pre>usefull</Pre> or it may <pre>
    not
    be usefull</pre> but its fun.
    </body>
    It should give,
    HA ha
    FUNNY
    usefull
    not
    be usefull
    Do the following,
    Create a file one.sed with following contents
    s/[<][Pp][rR][eE][>]/<PRE>/g
    s/[<]\/[Pp][rR][eE][>]/<\/PRE>/g
    Create a file two.awk with following contents
    gsub(/<PRE>/,"\n<PRE>");
    if (substr($0,1,6) != "</PRE>") {gsub(/<\/PRE>/,"\n<\/PRE>");}
    print
    Create a file three.awk with following contents
    BEGIN{v1=0}
    if ( match($0,/<\/PRE>/) != 0 ) { v1 = 0;}
    if ( match($0,/<PRE>/) != 0 ) { v1 = 1 ;}
    if (v1 == 1) { gsub(/<PRE>/,"");if (length($0) != 0) {print $0;} }
    And finally run the command,
    sed -f one.sed f.html | nawk -f two.awk | nawk -f three.awk
    Its not complex.
    one.sed will convert all <pre> tags to all capital letters.
    two.awk will move all <PRE> and </PRE> tags on new line, means <PRE> and </PRE> will always be first string in a line or it will not be there.
    three.awk will print out the actual contents between <PRE> and </PRE> pairs.
    If your requirement is even more complex then what I have done, please use perl instead of shell. Also, perl is consistant across Unix platforms. sed and awk are not. On Solaris you will have to use 'nawk' but on HP/AIX you have to use 'awk' and on Linux you may have to use 'gawk'.
    Cheers....have fun.
    Let me know any further complications and if you need a perl script.

  • Startup shell script help for newbie?

    New to UNIX (linux)... need the bash shell script commands for my r.c local file to start my services when server boots.
    I got my ds, dps and admin server in their respective /opt directories. I need the shell commands to have these start. Of course I can start them manually but when I try a line like this in a script, it doesnt work:
    ./var/opt/sun/directory-server/slapd-dsserver/start-dsserver
    Some path problem or dot thing?

    There are a few other things you may want to consider, such as what the default browser is, are tabs being used, is the page loaded yet, etc, but Safari has a do javascript command in it's scripting dictionary. The following script will open a new document and run your specified javascript, or you can go to their NPR Program Stream Page and download a playlist that will run directly from iTunes.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 335px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set my_script to "NPR.Player.openPlayer(2, 0, '03-21-2008', NPR.Player.Action.PLAY_NOW, NPR.Player.Type.PROGRAM, NPR.Player.Mode.LIVE)"
    tell application "Safari"
    activate
    set the URL of the front document to "http://www.npr.org/"
    if my page_loaded(20) is false then error numner - 128 -- page not loaded in time
    do JavaScript my_script in document 1
    end tell
    on page_loaded(timeout_value) -- from http://www.apple.com/applescript/archive/safari/jscript.01.html
    delay 2
    repeat with i from 1 to the timeout_value
    tell application "Safari"
    if (do JavaScript "document.readyState" in document 1) is "complete" then
    return true
    else if i is the timeout_value then
    return false
    else
    delay 1
    end if
    end tell
    end repeat
    return false
    end page_loaded
    </pre>

  • Issue in running eCATT Scripts  - Help required very urgently

    Dear All,
    We are running the eCATT scripts from Solman 7.0 by connecting it to ERP system R/3 4.6C. While running the scripts, we are facing some issue.
    1. If we try to run the scripts then those are getting failed. The same scripts if we run after some time with out changing any code then those are running fine.
    We are frequently facing this probelm.
    Could you please let me know the solution. Your help is really appreciated.
    Thanks,
    Mahendra
    Moderator Message: Urgently word is not allowed in this forum. Open a new thread without the "priority" word.
    Edited by: kishan P on Sep 6, 2010 11:18 AM
    Edited by: kishan P on Sep 6, 2010 11:21 AM

    Dear Ananth,
    Scripting is getting failed at different lines of code at different runs.
    Thanks,
    Mahendra

  • Java Script (Help Required)

    We are using the following code in HTML Header of the page
    //replaces the enter key with the tab key
    document.onkeydown = function ()
    if (event.keyCode == 13)
    event.keyCode=9;
    </script>
    We want to execute this code when current Item is not :P3_REMARKS (which is text area)
    Regards
    Jazib

    example of a name of an item
    About Referencing Items Using JavaScript
    When you reference an item, the best approach is to reference by ID. If you view the HTML source of an Oracle HTML DB page in a Web browser, you would notice that all items have an ID attribute. This ID corresponds to the name of the item, not the item label. For example, if you create an item with the name P1_FIRST_NAME and a label of First Name, the ID will be P1_FIRST_NAME.
    Knowing the item ID enables you to use the JavaScript function getElementById to get and set item attributes and values. The following example demonstrates how to reference an item by ID and display its value in an alert box.
    <script language="JavaScript1.1" type="text/javascript">
    function firstName(){   
    alert('First Name is ' + document.getElementById('P1_FIRST_NAME').value );
    // or a more generic version would be
    function displayValue(id){   
    alert('The Value is ' + document.getElementById(id).value );
    </script>
    // Then add the following to the "Form Element Attributes" Attribute of the item:
    onChange="javascript:displayValue('P1_FIRST_NAME');"
    Kind regards,
    Iloon

  • Script Help required to Auto-populate the Time Period Value

    Hi Experts ,
                    Time Period object was defined in System
    I have a collection M_ED_SYS_CE with M_ED_YR as collection field .
    M_ED_YR field is a Time Period Picker (i.e. values are like "Year 2011" , Year 2010)
    my requirement was to auto-populate the M_ED_YR collection field with Time Period object . No manual Interruption
    Also I need to increment and auto-popualte & set  the Time Period values for all  existing M_ED_YR Collection fields .
    Can any one please clarify if TimePeriod objects defined in System is of VLV type or String Objects
    Any suggestions are highly Apprecaited .
    thanks in Advance
    Tayi

    REsolved

  • Run shell script as root on boot

    Hi!
    I have the need to run a shell script on boot up as root.
    It will not run as any other user because the software that the shell script runs requires root permissions, and I don't use my computer as root. I can't run it at login and use sudo because it would ask for a password and hang.
    How can I have the shell script auto-run at boot (or login) as root?
    Thanks
    Ross

    Hi,
    first of all you can store your shell script anywhere on your system, I prefere the location /usr/local/scripts (this doesn't exist by default).
    Second you have to create a LaunchDeamon script in /Library/LaunchDeamons which execute your shell script at boot as root.
    An example:
    -------------------------snip------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST
    1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>YOURIDENTIFIERNAME</string>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/scripts/YOUR_SCRIPT.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>ROOT</string>
    <key>GroupName</key>
    <string>WHEEL</string>
    </dict>
    </plist>
    -------------------------snap------------------------
    http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemS tartup/Articles/LaunchOnDemandDaemons.html
    To run a script as root during a user login you can configure a LoginHook. To create a LoginHook login as the relating user and type the following commad:
    sudo defaults write com.apple.loginwindow LoginHook /Path/To/Your/Script
    http://support.apple.com/kb/HT2420
    Hope that helps
    Bye Tom

  • Trying to create a shell script to cut/paste files in finder. Help needed.

    I'm trying to create an automator shell script to cut/paste. It'll function exactly like copy/paste. i.e. I'll just copy file/files with command+c like always, but then I'll create an automator which uses the "mv" terminal app to move the files which works exactly like cut paste.
    I need some help since I don't know the syntax for creating shell scripts.
    What I did so far is to do it in automator with Apple Script which goes like the following:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    tell application "Terminal"
    do script with command "mv \"" & input & "\"" & thePath in window 1
    end tell
    return input
    end run
    This gets the copied file path from clipboard before, as input, and then recognizes the active finder window as thePath so then executes the mv command for the input file to the thePath window.
    It doesn't work as expected since it connects both file/window paths into a single path instead of leaving a space between them so the mv command can't recognize two separate paths.
    What's the correct syntax for that line
    do script with command "mv \"" & input & "\"" & thePath in window 1
    to leave a space between input and thePath under the mv command?
    Also this requires the terminal app to be open in the background.
    After I get this to work I want to do the exact same thing using shell script within automator, so I won't need Terminal to be open all the time.
    And the next step will be to cut/paste multiple files/folders but that should be easy to do once I get the hang of it.

    Try using:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    do shell script "mv \"" & input & "\" " & thePath
    return input
    end run
    (45977)

  • Need help in Shell Scripts

    Hi,
    I have a requirement need a help.
    Requirement states like this:
    I need to write a shell script through which I need to search a huge lines code and to find out following information :
    1. Total No of lines of the code
    2. No of DML statements (select,update,insert, delete) used like how many SELECT, How many UPDATE etc used in it.
    3. No of base apps tables referenced like How many tables starting with "CMF_" is present.
    4. No of procedure calls like how many procedures starting with "PROC_" used.
    Can anyone help me in this ? I need to script.
    My Unix version is :
    $ uname -a
    SunOS appsnet 5.6 Generic_105181-21 sun4u sparc SUNW,Ultra-4
    Thanks in advance
    [email protected]

    What you need here is a AWK script. This script will read the input as the source file (as command line
    argument or as standard input), and process each like of the file read to look for the different patterns
    in that line (looking for example if the line contans "SELECT " or "INSERT " etc...) and increment its
    corresponding count. At the end of the script in the END section you can get the number of lines with the
    NR awk inbuilt variable.
    Hope this helps.
    Hi,
    I have a requirement need a help.
    Requirement states like this:
    I need to write a shell script through which I need to search a huge lines code and to find out following information :
    1. Total No of lines of the code
    2. No of DML statements (select,update,insert, delete) used like how many SELECT, How many UPDATE etc used in it.
    3. No of base apps tables referenced like How many tables starting with "CMF_" is present.
    4. No of procedure calls like how many procedures starting with "PROC_" used.
    Can anyone help me in this ? I need to script.
    My Unix version is :
    $ uname -a
    SunOS appsnet 5.6 Generic_105181-21 sun4u sparc SUNW,Ultra-4
    Thanks in advance
    [email protected]

  • Need Help in creating Unix Shell Script for database

    Would be appreciable if some one can help in creating unix shell script for the Oracle DB 10,11g.
    Here is the condition which i want to implement.
    1. Create shell script to create the database with 10GB TB SPACE and 3 groups of redo log file(Each 300MB).
    2. Increase size of redolog file.
    3. Load sample schema.
    4. dump the schema.
    5. Create empty db (Script should check if db already exists and drop it in this case).
    6. Create backup using rman.
    7. restore backup which you have backed up.

    This isn't much of a "code-sharing" site but a "knowledge-sharing" site.  Code posted me may be from a questioner who has a problem / issue / error with his code.   But we don't generally see people writing entire scripts as responses to such questions as yours.  There may be other sites where you can get coding done "for free".
    What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
    But the expectation here is for you to write your own code.
    Hemant K Chitale

  • Please help me remove the last elements of shell script from my applescript

    I read somewhere that running a shell script in an applescript was inefficient and created extra overhead, fine, so I am trying to take all of my shell script out of my applescript (this should fix issues with forward slashes in names as well...)
    however I am stuck on these last two lines (I know they are probably trivial but I've been up waaaay too long now) so I was wondering if anyone would be awesome enough to show me how to convert the bash to applescript.
    --does a recursive copy and rename
    do shell script "cp -R " & (thePath as text) & " " & (theOtherPathWithFile as text)
    --does a copy and rename, then a simple move
    do shell script "cp " & (quoted form of (POSIX path of this_item as text)) & " " & (theNewPath as text) & "&& mv " & (theOtherPathWithFile as text) & " ~/Desktop"
    Any and all help will be appreciated.

    There isn't anything wrong with using shell scripts, especially since AppleScript is designed to do this very thing. There is some overhead when using do shell script, just as there is some overhead when using an application tell statement, so it just depends on what you are doing.
    The performance of any particular script would also be up to whatever is acceptable to you (or your customers), and sometimes a shell script is the most efficient way to do something. Many of the system utilities are just GUI front-ends to a shell script, so they can't be all bad.
    To do your file copy or move with the Finder, you will need to tell it to duplicate or move the item(s) (there is that pesky overhead again). Shell scripts use POSIX paths while the Finder uses colons as its path delimiter, so you will need to use the correct file path references - there is a decent article about that at Satimage. Once your file paths have been defined (or using something like choose file or choose folder)), your script would be something like:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder"
    duplicate source to destination
    -- move source to destination
    end tell
    </pre>
    See the Finder and *System Events* scripting dictionaries for more information about the ways they deal with files.

  • Help changing permissions using a shell script

    Hey,
    Here's the situation. We have 18 Macs, they're all cloned from a master image and have 2 local accounts - Administrator and Student.
    There are some files on the machines that the student account does not have permission to access, but it's critical that they do. I've written a shell script to change the files so that everyone has permission to read, write and execute them:
    #! /bin/bash
    clear
    sudo chmod ugo+rwx /Library/Audio/Plug-ins/Components/FM8.component
    sudo chmod ugo+rwx /Library/Audio/Plug-ins/VST/FM8.vst
    sudo chmod ugo+rwx /Library/Audio/Plug-ins/VST/FM8\ FX.vst
    sudo chmod ugo+rwx /Library/Application\ Support/Digidesign/Plug-ins/FM8.dpm
    In theory, this means I can just run the script, type the admin password in once and its done (as opposed to typing in the password 4 times and navigating to each file individually.)
    However, this doesn't quite work as planned.
    If I run the script, navigate to the files using the Finder and 'get info' it declares that "Everyone" can "Read & Write". The student account can see the file properly, but the finder just thinks there's nothing there (Size=Zero KB.) Only when I explicitly add the Student account (Add->Student) and set it to "Read & Write" does it start working.
    2 questions really - Why does it do this, and how do I make it work?
    It was my understanding that if everyone could read, write and execute there wouldn't be a problem, regardless of which account tries to access the file?
    Also, if there is a better/easier/faster way of doing the same thing I'm open to suggestions.
    Thanks.

    Thanks Tony,
    Your reply was helpful, I didn't realise you could tie all the paths together and just use one chmod command.
    I actually solved the issues myself this morning (fresh head on after a good nights sleep!)
    It turns out the 'files' I'm trying to modify aren't strictly files at all, they're packages. Using just chmod changes permissions for the top of the package only (hence why I could see the files but they said Zero KB.)
    adding -R to the chmod modified permissions to everything inside the package as well, which has resolved the issue.
    Thanks for the help though!

Maybe you are looking for

  • Why doesn't my hp pc recognize my ipod touch 5th gen

    Have a new Ipod Touch 5th gen, that is not being recognized by my hp pc...also have downloaded Itunes and Quickstart, but nothing seems to help...my ipod does seem to charge while being connected there is no indication that it's even connected. Can t

  • Are you having success and getting value from "Month 13" in GL?

    We are looking at using month 13 in the JDE GL. Am interested in use cases of other customers where they have either: - tried out month 13 and got good value from it (if so what was the value) - have tried month 13 out and decided not to use it (why?

  • Problem with Xelsius Integration

    Hi, I have installed licenced version of Business Objects Edge Client tools and also integration kit and Xelsius. When I open the xelsius and trying to connect through manage connection - Data manager -Query As  A Web service - getting problem with U

  • Rman dupicate db skip tablespace not working reserved words with quoates

    This is how the script looks like set newname for datafile '/oracle/oracle10.2/oradata/smalldb/users01.dbf' to '/oracle/staging/TEST1/users01.dbf'; set newname for datafile '/oracle/oracle10.2/oradata/smalldb/system01.dbf' to '/oracle/staging/TEST1/s

  • Wsdd-merge to merge web-services.xml where is Ant Task

    Can anyone tell me the the java class for the <wsdd-merge> ant target, I am using Ant 1.6.1 and need to add the taskdef e.g.:- <taskdef name="wsdd-merge" classname="???/" /> many thanks.