Simple bash-batch-compiler improvements

hey there,
i made a simple bash script for compiling many *.cpp files in one dir.
#! /bin/bash
find . -name "*.cpp" -exec g++ {} -o {}.sh \;
but if an *.sh already exists it shouldn't compile, also it would be nice to have it named program.sh not program.cpp.sh my bash skills are rather limited, think one could help me out folks
cheers,
detto

Mh, got another one here :< Still didn't find a GOOD sed tutorial with regexp. It's so damn complicated in my eyes.
Well, I figured something out, but it has a error inside
for f in *.jpg ; do mv "$f" `echo "$f" | sed 's! 1280!!'` ; done
When executing it prompts for every *jpg file with "mv: specified target »(10).jpg« is no directory". :?
Last edited by detto (2007-03-15 13:26:52)

Similar Messages

  • Watchless - a simple Bash helper for LESS to CSS compilation

    Here is a simple Bash tool for LESS files compilation, watching your .less files using inotifywait and compiling CSS on file change.
    Supports @import-ed files. Compiled files can go in the current directory or in another directory, keeping the directory structure intact (~/Project/less/style.less to ~/Project/css/style.css for example)
    Not well tested, may be dangerous.
    AUR: https://aur.archlinux.org/packages/watchless/

    I place all my LESS files, along with all of the JavaScript files in a sub-directory called _src (for source files). The _scr folder is Cloaked so that it is not included in file transfers. The structure looks like
    _src
        js
              bootstrap
                  ..... // files go here
              fonts
                  ..... // files go here
              jquery
                  ..... // files go here
              myscripts.js // scripts of my own that I want added
              scripts.js  // contains imported JS files that are combined and minified into one production script
        less
              bootstrap
                  ..... // files go here
              fonts
                  ..... // files go here
              footer.less //
              form.less //
              header.less  // these files are for the various parts of the template and or documents
              main.less //
              nav.less //
              styles.less // contains imported LESS files that are combined and minified into one production style sheet
    I will then use PrePros to compile the JS and CSS files making for just two HTTP requests.
    Have a look at source code (lines 7 and 110) of this site.
    Incidentally, by using PrePros, not only do the LESS and JS files get compiled automatically, any saved changes are immediately visible in my browser without having to refresh each time.

  • Shell script for batch compilation of forms 10g on AIX 5.3L AS

    Hi All,
    Can anybody provide me the Shell script for batch compilation of forms 10g and reports 10g on AIX 5.3L AS?
    Regards,
    SAM

    Hi Alex,
    I tried with the below script as well as the one you had posted.
    ORACLE_HOME=/opt/oracle/OraHome_3
    export ORACLE_HOME
    TNS_ADMIN=$ORACLE_HOME/network/admin
    export TNS_ADMIN
    LIBPATH=$ORACLE_HOME/lib32:$ORACLE_HOME/jdk/jre/bin:$ORACLE_HOME/jdk/jre/bin/cla
    ssic:$LIBPATH
    export LIBPATH
    cd ../forms
    for i in `ls *.pll`
    do
    echo Compiling Library $i ....
    $ORACLE_HOME/bin/frmcmp module=$i userid=mydbuser/mydbuser@mydb
    batch=yes module_type=library
    compile_all=yes window_state=minimize
    done
    export ORACLE_HOME=/opt/oracle/OraHome_3
    export ORACLE_TERM=vt220
    export LD_LIBRARY_PATH=/opt/oracle/OraHome_3/lib:/opt/oracle/OraHome_3/jdk/jre/l
    ib:/opt/oracle/OraHome_3/jdk/jre/lib/i386:
    cd ../forms
    for i in `ls *.pll`
    do
    echo "Compiling Library $i ...."
    /opt/oracle/OraHome_3/bin/frmcmp module_type=form userid=mydbuser/mydbuser@mydb
    module=$i batch=yes compile_all=no
    window_state=minimize upgrade=no
    done
    echo "PLL Compilation done"
    But there was a same kind of error thst turning up all the time.
    Compiling Library Agf.pll ....
    Forms 10.1 (Form Compiler) Version 10.1.2.0.2 (Production)
    Forms 10.1 (Form Compiler): Release - Production
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    PL/SQL Version 10.1.0.4.2 (Production)
    Oracle Procedure Builder V10.1.2.0.2 - Production
    Oracle Virtual Graphics System Version 10.1.2.0.0 (Production)
    Oracle Multimedia Version 10.1.2.0.2 (Production)
    Oracle Tools Integration Version 10.1.2.0.2 (Production)
    Oracle Tools Common Area Version 10.1.2.0.2
    Oracle CORE 10.1.0.4.0 Production
    FRM-10043: Cannot open file.
    Form not created
    I hence updated the permissions on the pll as below
    -rwxrwxrwx 1 oracle oinstall 335872 May 19 16:31 Agf.pll
    But the problem is still persisting.
    My environment details are as below.
    I am working on Win XP machine. Connected to my AS via telnet and xmanager. I have set my DISPLAY to my local IP.
    Is there any thing more that I need to do? If so then let me know.
    Regards,
    SAM

  • Batch Compilation Problem(Migration)

    Hiiiiiiiiiii Gurus..
    I am on Migration Project...... and for batch compilation of Reports do any one give me the Script.. Because whatever I have is not working.
    I have no errors but also I can't get the error file,log file,output file.
    (Migration is from 5 to 10g)
    Can any one help me.........
    Regards Madhav

    Here is what I use on windows (file is called genforms.bat):
    echo "Generating PLSQL libraries"
    echo "Generating abc10.pll"
    ifcmp90.exe module=abc10.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating abc20.pll"
    ifcmp90.exe module=abc20.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating abc30.pll"
    ifcmp90.exe module=abc30.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating menus"
    echo "Generating abc10.mmb"
    ifcmp90.exe module=abc10.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating abc20.mmb"
    ifcmp90.exe module=abc20.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating abc30.mmb"
    ifcmp90.exe module=abc30.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating forms"
    echo "Generating abc101.fmb"
    ifcmp90.exe module=abc101.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=y
    echo "Generating abc102.fmb"
    ifcmp90.exe module=abc102.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=y
    echo "Generating abc103.fmb"
    ifcmp90.exe module=abc103.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=yUsage is:
    C:\dev><b>genforms.bat > genforms.log</b>For unix you will have to use (file is called genforms.sh):
    echo "Generating PLSQL libraries"
    echo "Generating abc10.pll"
    ifcmp90 module=abc10.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating abc20.pll"
    ifcmp90 module=abc20.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating abc30.pll"
    ifcmp90 module=abc30.pll userid=hr/hr@db module_type=library logon=y batch=n build=y compile_all=y
    echo "Generating menus"
    echo "Generating abc10.mmb"
    ifcmp90 module=abc10.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating abc20.mmb"
    ifcmp90 module=abc20.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating abc30.mmb"
    ifcmp90 module=abc30.mmb userid=hr/hr@db module_type=menu logon=y batch=n build=y compile_all=y
    echo "Generating forms"
    echo "Generating abc101.fmb"
    ifcmp90 module=abc101.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=y
    echo "Generating abc102.fmb"
    ifcmp90 module=abc102.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=y
    echo "Generating abc103.fmb"
    ifcmp90 module=abc103.fmb userid=hr/hr@db module_type=form logon=y batch=n build=y compile_all=yUsage is:
    server:/u1/app/oracle% <b>genforms.sh >> genforms.log</b>Not sure what version you are migrating from, I don't think version 5 of reports exists.

  • Simple bash scripting help needed..

    I want to learn som simple bash scripting in order to automate various tasks.. Im totally noob, so bear with me
    First of all I would like to set configs without using nano.. is there a simple command for this? For example if i want change my hostname in /etc/rc.conf.. how can i print the current vallue and how can i change it`?
    i was thinking something like this to get the current value:
    # cat /etc/rc.conf | grep HOSTNAME=
    which returns HOSTNAME="myhostname"
    how can i change this value with one or more commands whitout touching the rest of the file?

    abesto wrote:
    A slightly naive solution:
    CHOICE="lisa"
    NAMES="homer marge lisa bart maggie"
    if [ "`echo \" $NAMES \" | grep \" $CHOICE \"`" ]; then
    echo "this is how you do it"
    fi
    The extra spaces inside the escaped quotes are to ensure that only a whole word is "matched".
    You can also replace the elif's with a loop through a list of "the other variables". Then you'd use the loop variable instead of $CHOICE above.
    grep can check on word-bounderies with \< and \>, or with the -w switch. The -q switch suppresses any messages and exits with exit-code 0 when the first match is found:
    if echo "${NAMES}" | grep -qw "${CHOICE}"; then
    Nice and readable, should work, but i haven't tested it
    EDIT:
    Procyon wrote:CHOICE="lisa"
    NAMES="homer marge lisa bart maggie"
    if [[ $NAMES =~ $CHOICE ]]; then echo match; fi
    This one also matches elisa, ie. no check on word bounderies. You should be carefull with that
    Last edited by klixon (2009-04-23 09:40:22)

  • Forms 11g Batch Compilation Script

    Hi,
    I have seen few threads in this forum on the topic "Batch Compilation of Forms"
    For instance batch file to convert fmb to fmx
    But i could not find a way to do the batch compilation in Forms 11g?
    How do I batch compile my Forms in 11g?
    Thanks,
    Ram

    Nothing has changed from the old versions to version 11. Compilation is done the same way as it always has in the past. The only difference (depending on which version you start from) is the the name and location of the compiler executible. The new file name is frmcmp (.exe if you are using Windows and .sh for Unix). All old example scripts should work in the new version as long as you make this change.

  • Solaris 11 - run a simple BASH script on computer startup

    I need to have a simple BASH script run on my Solaris 11 machine automatically whenever the computer (re)starts. It should be run with root permissions and after the computer has fully booted. What is the easiest way to do that?
    Thank you
    Dusan

    Hi user9368043
    Yes, that should be right, and be intended this way.
    See /etc/rc3.d/README and the following part from smf(5):
    Legacy Startup Scripts
    Startup programs in the /etc/rc?.d directories are executed
    as part of the corresponding run-level milestone:
    /etc/rcS.d milestone/single-user:default
    /etc/rc2.d milestone/multi-user:default
    /etc/rc3.d milestone/multi-user-server:default
    Your question concerning upgrading to Solaris 11.1:
    In the Gnome menus, you should look for (and start)
    System --> Administration --> Update Manager
    Let it do its work. It will give you a new boot environment, containing Solaris 11.1. Possibly, you have to perform upgrading twice. With "beadm activate", see beadm(1M), you can go back to Solaris 11.0 whenever you want.
    "Local" parts of your zfs root pool, like /usr/local, home directories, /root, and so on, should be in separated file systems, and be mounted outside the root pool before upgrading. They are availlable then from any boot environment, and will not be duplicated. See more in zfs(1M), zpool(1M).
    I strongly recommend upgrading. Solaris 11.1 is great.

  • How to batch compile Oracle Reports ?(just like the code for compiling forms)

    The following is for Batch compiling forms..
    IF %1=="" GOTO END
    DEL *.FMX
    FOR %%F IN (*.FMB) DO START /W Ifcmp60 USERID=%1 BATCH=Y MODULE=%
    %F
    :END
    Any idea for compiling all reports using a technique just like
    this..

    User dbms_ldap package in the database to use PL SQL to create your database
    account and then an OID account with a RAD to match the database login. If you
    You may have to load the DBMS_Ldap package from the database ADMIN directory first to be available in the database.
    LDAP SQL Ex.
    user_username := LOWER(new_user) || '@domain.com'; -
    retval := dbms_ldap.search_s(my_session, ldap_base,
    dbms_ldap.scope_subtree, 'uid=' || user_username, my_attrs, 0,
    my_message);
    retval := dbms_ldap.count_entries(my_session, my_message);
    my_entry := dbms_ldap.first_entry(my_session,my_message);
    my_dn := dbms_ldap.get_dn(my_session,my_entry);
    dbpassword := 'PASSWD01';
    isvalidrad := forms_rad.newraddefinition(radname,new_user,dbpassword,
    dbtnsnames,errormessage);
    sessionestablished := forms_rad.createoidsession(ldap_user, ldap_passwd,
    ldap_host, ldap_port, ldap_base);
    radcreated := forms_rad.createradforcn(my_dn, 'false', errormessage);
    -- Create new user's database account same as RAD account.
    v_sql := 'CREATE USER "' || new_user || '" IDENTIFIED BY ' || dbpassword ||
    ' DEFAULT TABLESPACE JLIM TEMPORARY TABLESPACE TEMP';
    EXECUTE IMMEDIATE v_sql;
    v_sql := 'GRANT CONNECT TO ' || new_user;
    EXECUTE IMMEDIATE v_sql;

  • Simple BASH script to update subversion files

    This is just a simple BASH script that will update all .svn files in a specified directory.  If an update fails, it will attempt to update all the subdirectories in the failed one, so as much will be updated as possible.  Theoretically, you should be able to supply this script with only your root directory ( / ), and all the .svn files on your computer will be updated.
    #! /bin/bash
    # Contributor: Dylon Edwards <[email protected]>
    # ================================
    # svnup: Updates subversion files.
    # ================================
    #  If the user supplies no arguments
    #+ then, update the current directory
    #+ else, update each of those specified
    [[ $# == 0 ]] \
        && dirs=($PWD) \
        || dirs=($@)
    # Update the target directories
    for target in ${dirs[@]}; do
        # If the target file contains a .svn file
        if [[ -d $target/.svn ]]; then
            # Update the target
            svn up $target || {
                # If the update fails, update each of its subdirectories
                for subdir in $( ls $target ); do
                    [[ -d $target/$subdir ]] &&
                        ( svnup $target/$subdir )
                done
        # If the target file doesn't contain a .svn file
        else
            # Update each of its subdirectories
            for subdir in $( ls $target ); do
                [[ -d $target/$subdir ]] &&
                    ( svnup $target/$subdir )
            done;
        fi
    done

    Cerebral wrote:
    To filter out blank lines, you could just modify the awk command:
    ${exec awk '!/^$/ { print "-", $_ }' stuffigottado.txt}
    very nice; awk and grep: two commands that never cease to amaze me.

  • Simple bash menu

    I wanted a simple bash menu where arrow keys could be used to select items. So here it is. It requires cuu and cud in the teminfo or it fails to look nice.
    Example usage, distro="`smenu ArchLinux Debian Ubuntu Gentoo`"
    Feel free to modify and adapt for your own personal usage.
    #!/bin/bash
    # input: list of menu items
    # output: item selected
    # exit codes: 0 - normal, 1 - abort, 2 - no menu items, 3 - too many items
    # to select item, press enter; to abort press q
    [[ $# -lt 1 ]] && exit 2 # no menu items, at least 1 required
    [[ $# -gt $(( `tput lines` - 1 )) ]] && exit 3 # more items than rows
    # set colors
    cn="`echo -e '\r\e[0;1m'`" # normal
    cr="`echo -e '\r\e[1;7m'`" # reverse
    # keys
    au="`echo -e '\e[A'`" # arrow up
    ad="`echo -e '\e[B'`" # arrow down
    ec="`echo -e '\e'`" # escape
    nl="`echo -e '\n'`" # newline
    tn="$#" # total number of items
    { # capture stdout to stderr
    tput civis # hide cursor
    cp=1 # current position
    end=false
    while ! $end
    do
    for i in `seq 1 $tn`
    do
    echo -n "$cn"
    [[ $cp == $i ]] && echo -n "$cr"
    eval "echo \$$i"
    done
    read -sn 1 key
    [[ "$key" == "$ec" ]] &&
    read -sn 2 k2
    key="$key$k2"
    case "$key" in
    "$au")
    cp=$(( cp - 1 ))
    [[ $cp == 0 ]] && cp=$tn
    "$ad")
    cp=$(( cp + 1 ))
    [[ $cp == $(( tn + 1 )) ]] && cp=1
    "$nl")
    si=true
    end=true
    "q")
    si=false
    end=true
    esac
    tput cuu $tn
    done
    tput cud $(( tn - 1 ))
    tput cnorm # unhide cursor
    echo "$cn" # normal colors
    } >&2 # end capture
    $si && eval "echo \$$cp"
    # eof
    Last edited by fsckd (2010-09-29 21:31:17)

    livibetter wrote:
    Nice code.
    I manually added j, k, and o (~Return) into the key checking part. I could use j,k or up,down to choose, but I wonder if that possible you can re-code to make it can accept multiple keys set in $au,$ad, and $nl.
    Thanks. In the case statement you can add multiple keys, like:
    "$au"|k)
    <snip>
    "$ad"|j)
    livibetter wrote:Also, a new option to clean up the menu after user choice or leave?
    I didn't want this which is why it's not in the script. At the bottom of the script, change tput cud $(( tn - 1 )) to tput dl $tn ; tput cuu1 and it should delete the lines.
    Bug: does not work with fish shell, set distro (./smenu ArchLinux Debian Ubuntu Gentoo); I wonder how it fares with other shells and terminals.

  • RH9 Batch Compile Failures

    I have a batch file set up to batch compile numerous projects one after the other for RoboHelp 9. The output is CHM format. When doing the compile, usually at least one project fails to completely compile and the log file shows only this information:
    Adobe (R) RoboHelp Project Command Line Compiler version 9.0.0.228
    Copyright (C) 2006-2007, Adobe Systems Incorporated and its licensors. All rights reserved.
    Project: C:\TechComm\SPIRIT\source\projects\directd\directd.xpj
    Layout: ssl_directd_hdi.
    Output: C:\TechComm\SPIRIT\output\help\directdhdi.chm.
    Scanning project for compilation....
    Scanning finished.
    Warning: No baggage file description.
    There are no files attached to the project. The baggage file contains some CHMs that were used for remote links, but they are not included in the project.
    Additionally, if I recompile this project using the batch file, it will build fine. How can I stop these initial failures? It's not just this project, but others will randomly not generate and the log file shows the same information.

    Thanks for your suggestions.
    Matt, I have tried "Mass Compile" and it is nothing to do with the FPGA. It just opens all your VIs, resaves them, and relinks them to their subVIs. This helps with some cross-linking issues.
    Bruce, the behavior you describe is what I would have expected initially. However, it seems like I do have to recompile all the subVIs. Right now I don't see anything changing on the FPGA side if I recompile my FPGA shell VI, but not my subVIs.
    It makes some sense that compiling the FPGA shell VI would not automatically recompile all the subVIs - the full compile including all subVIs takes about three hours, as compared to less than an hour to recompile the shell VI alone. So there is a strong reason to want subVI compiles to be independent of the shell compile.
    Thanks,
    Dave

  • Batch compile for FPGA?

    Dear all,
    I have an FPGA VI with many subVIs in my project. I would like to compile the entire project at once, but I can't seem to find a way to do this. So right now I have to pull up 30+ subVIs individually and compile them at the rate of about one every 20 minutes, which is really inconvenient.
    Is there any way to do a batch compile of my project?
    Thanks,
    Dave Kielpinski

    Thanks for your suggestions.
    Matt, I have tried "Mass Compile" and it is nothing to do with the FPGA. It just opens all your VIs, resaves them, and relinks them to their subVIs. This helps with some cross-linking issues.
    Bruce, the behavior you describe is what I would have expected initially. However, it seems like I do have to recompile all the subVIs. Right now I don't see anything changing on the FPGA side if I recompile my FPGA shell VI, but not my subVIs.
    It makes some sense that compiling the FPGA shell VI would not automatically recompile all the subVIs - the full compile including all subVIs takes about three hours, as compared to less than an hour to recompile the shell VI alone. So there is a strong reason to want subVI compiles to be independent of the shell compile.
    Thanks,
    Dave

  • Batch Compilation of Reports

    Hi ,
    I have followed the Note:191529.1 and developed a script for a batch compilation.
    #UNIX COMPILE REPORTS
    #compile_rep.sh
    for i in `ls *.rdf`
    do
    echo Compiling Report $i ...
    rwconverter.sh userid=scott/tiger@bs817 batch=yes source=$i
    stype=rdffile dtype=repfile overwrite=yes
    done
    My Code:
    for i in `/letters_reports/acesrdf_10/ *.rdf`
    do
    echo Compiling Report $i ...
    rwconverter.sh userid=aces/aces@acesdev1 batch=yes source=$i
    stype=rdffile dtype=repfile overwrite=yes
    done
    --- i am getting the below error for the script.
    "compile_rep.sh: line 21: /letters_reports/acesrdf_10/: is a directory"
    if i try to test the script for one single report i get the below error:
    "compile_rep.sh: line 21: /letters_reports/acesrdf_10/LE-CMG002A.RDF: cannot execute binary file".
    Please let me know the correct way.
    Thanks,
    Yugi

    U could try this:
    for i in `ls /letters_reports/acesrdf_10/ *.rdf`
    do
    echo Compiling Report $i ...
    rwconverter.sh userid=aces/aces@acesdev1 batch=yes source=$i
    stype=rdffile dtype=repfile overwrite=yes
    done
    If it works, u forgot the "ls" in your loop.
    Grtz

  • Another simple bash script to clean pacman cache

    here is a simple script that I have written which cleans pacman cache folder in a way that only the packages which are now "updated" in the repositories, will get removed. This is different from what "pacman -Sc" does. pacman -Sc also removes any package which is not installed, while this script keeps all the packages which are updated whether they are installed or not.
    The functionality is some how like what "apt-get autoclean" does in debian.
    to use this script you need to run it with "list" or "clean" arguments.  you can also use the "help" argument for more help.
    I hope it helps
    #! /bin/bash
    # clcache - This script cleans pacman cache folder in a way that only the packages
    #+ which are now updated in the repositories, will get removed. This is
    #+ different from what "pacman -Sc" does. pacman -Sc also removes any package
    #+ which is not installed, while this script keeps all the packages which are
    #+ updated whether they are installed or not.
    # I have tweaked this script to be as fast as possible, it might still need a
    #+ couple of minutes to compelete based on the size of your cache folder.
    # to use this script you need to run it with "list" or "clean" arguments.
    # you can also use the "help" argument for more help.
    # This script is written by "Ali Mousavi". Please report bugs to [email protected]
    DIR="/var/cache/pacman/pkg" #the default directory of pacman cache.
    ROOT_UID=0 #Only users with $UID 0 have root privilages.
    TMPFILE="/tmp/cache.tmp"
    # Run as root
    if [ "$UID" -ne "$ROOT_UID" ]
    then
    echo "Must be root to run this script"
    exit 1
    fi
    # Check for the arguments
    if [ -z "$1" ]
    then
    echo -e 'What should I do?\nValid Argument are "list", "clean" or "help"'
    exit 1
    elif [ "$1" = "list" ]
    then
    ACTION="ls"
    MESSAGE="Are you sure you want to continue?"
    elif [ "$1" = "clean" ]
    then
    ACTION="rm -vf"
    MESSAGE="Are you sure you want to remove outdated packages? This process can not be undone!"
    elif [ "$1" = "help" -o "$1" = "-h" -o "$1" = "--help" ]
    then
    echo -e "This script checks the packages in your pacman cache directory and removes the packages that are outdated. It doesn't matter if the package is installed or not.\n\n3 arguments can be passed to the script:\n\nlist:\n\tchecks for package that are outdated and prints the names.\n\nclean:\n\tremoves outdated packages.\n\nhelp,-h,--help:\n\tprints this help text.\n\nThis script is written by \"Ali Mousavi\". Please report bugs to [email protected]"
    exit 0
    else
    echo 'Valid Argument are "list", "clean" or "help"'
    exit 1
    fi
    # Check if the user is sure!
    echo "This might take a while based on the amount of cached packages."
    echo -n "$MESSAGE(y/n) "
    read ANS
    if [ $ANS = "y" -o $ANS = "Y" -o $ANS = "yes" ]
    then
    echo "Processing packages..."
    elif [ $ANS = "n" -o $ANS = "N" -o $ANS = "No" ]
    then
    echo "Exiting on user request"
    exit 0
    else
    echo "Invalid answer"
    exit 1
    fi
    # Process the packages
    cd $DIR #change to cache directory.
    pacman -Sl | awk '{ print $2" "$3; }' > $TMPFILE
    for f in $(ls $DIR)
    do
    pname=$(file $f | cut -d: -f1) #Produces filename, like: fetchmail-6.3.19-1-i686.pkg.tar.xz"
    spname=$(echo $pname | sed 's/-[0-9][0-9]*.*//g') #removes package version: fetchmail
    pver=$(echo $pname | sed 's/.*-\([0-9\-\.][0-9\-\.]*-[0-9\-\.][0-9\-\.]*\).*/\1/g') #using pacman -Qi for all files takes a lot of time.
    if [ $(echo $pver | grep '[^0-9\-\.\-\-]' | wc -l) != 0 ] #checks if package version is alright
    then
    pver=$(pacman -Qpi $f | grep Version | awk '{print $3}')
    fi
    newpver=$(grep -e "^$spname " $TMPFILE | awk '{ print $2 }')
    if [[ $newpver != $pver ]]
    then
    $ACTION $f
    fi
    done
    rm -f $TMPFILE
    echo "Outdated packages processed successfully!"
    exit 0
    Last edited by tuxitop (2011-09-13 09:24:26)

    tuxitop wrote:# Check for the arguments
    if [ -z "$1" ]
    then
    echo -e 'What should I do?\nValid Argument are "list", "clean" or "help"'
    exit 1
    elif [ "$1" = "list" ]
    then
    ACTION="ls"
    MESSAGE="Are you sure you want to continue?"
    elif [ "$1" = "clean" ]
    then
    ACTION="rm -vf"
    MESSAGE="Are you sure you want to remove outdated packages? This process can not be undone!"
    elif [ "$1" = "help" -o "$1" = "-h" -o "$1" = "--help" ]
    then
    echo -e "This script checks the packages in your pacman cache directory and removes the packages that are outdated. It doesn't matter if the package is installed or not.\n\n3 arguments can be passed to the script:\n\nlist:\n\tchecks for package that are outdated and prints the names.\n\nclean:\n\tremoves outdated packages.\n\nhelp,-h,--help:\n\tprints this help text.\n\nThis script is written by \"Ali Mousavi\". Please report bugs to [email protected]"
    exit 0
    else
    echo 'Valid Argument are "list", "clean" or "help"'
    exit 1
    fi
    1. `echo -e 'foo\nbar\nbaz'` gets long and unreadable quickly. Instead, use here documents:
    cat <<EOF
    What should I do?
    Valid Argument are "list", "clean" or "help"
    EOF
    2. Use a case command, looks cleaner:
    case "$1" in
    list) ... ;;
    clean) ... ;;
    help|-h|--hep) ... ;;
    # Check if the user is sure!
    echo "This might take a while based on the amount of cached packages."
    echo -n "$MESSAGE(y/n) "
    read ANS
    if [ $ANS = "y" -o $ANS = "Y" -o $ANS = "yes" ]
    then
    echo "Processing packages..."
    elif [ $ANS = "n" -o $ANS = "N" -o $ANS = "No" ]
    then
    echo "Exiting on user request"
    exit 0
    else
    echo "Invalid answer"
    exit 1
    fi
    Try:
    read -p "hello: " -r
    echo $REPLY
    And again, `case` should be cleaner in this case.
    # Process the packages
    cd $DIR #change to cache directory.
    pacman -Sl | awk '{ print $2" "$3; }' > $TMPFILE
    While you quoted a lot, you left these two out. "$DIR" and "$TMPFILE" should be quoted, otherwise whitespaces will break the code.
    for f in $(ls $DIR)
    Apart from the same missing quotes, calling `ls` is a waste here. The following is sufficient and (maybe surprisingly) more accurate:
    for f in *
    How is it more accurate? Run this test script:
    #!/bin/bash
    DIR=/tmp/foo
    mkdir -p "$DIR"
    cd "$DIR"
    touch a\ b c$'\n'd
    for i in *; do
    printf '+%s+\n' "$i"
    done
    printf '%s\n' ---
    for i in $(ls $DIR); do
    printf '+%s+\n' "$i"
    done
    Let's not go too far here. Just get the idea.
    do
    pname=$(file $f | cut -d: -f1) #Produces filename, like: fetchmail-6.3.19-1-i686.pkg.tar.xz"
    Calling `file` here is, again, unnecessary. Also, filename of a package can contain ":", e.g., vi-1:050325-1-i686.pkg.tar.xz, which breaks your code.
    Don't complicate things:
    pname=$f
    spname=$(echo $pname | sed 's/-[0-9][0-9]*.*//g') #removes package version: fetchmail
    Broken for ntfs-3g-2011.4.12-1-i686.pkg.tar.xz, nvidia-173xx-utils-173.14.31-1-i686.pkg.tar.xz, etc...   Something less lousy:
    sed 's/\(-[^-]\+\)\{3\}$//' <<< "$pname"
    pver=$(echo $pname | sed 's/.*-\([0-9\-\.][0-9\-\.]*-[0-9\-\.][0-9\-\.]*\).*/\1/g') #using pacman -Qi for all files takes a lot of time.
    Although this might work for now, this would break if we had an architecture that starts with a digit, e.g. 686.  Something less lousy:
    sed 's/\(.*\)-\([^-]\+-[^-]\+\)-[^-]\+$/\2/' <<< "$pname"
    if [ $(echo $pver | grep '[^0-9\-\.\-\-]' | wc -l) != 0 ] #checks if package version is alright
    then
    pver=$(pacman -Qpi $f | grep Version | awk '{print $3}')
    fi
    Again, calling `wc` here is a waste. Anyway, why is this check necessary at all?
    newpver=$(grep -e "^$spname " $TMPFILE | awk '{ print $2 }')
    if [[ $newpver != $pver ]]
    then
    $ACTION $f
    fi
    done
    rm -f $TMPFILE
    echo "Outdated packages processed successfully!"
    exit 0
    The post is getting too long, so so much from me. If there's anything you don't understand yet, read bash(1).
    If I sound harsh or anything, don't be discouraged. Just keep reading, keep improving.
    Last edited by lolilolicon (2011-09-13 12:53:04)

  • Batch rename improvements

    While liking the batch rename feature, I'd like to suggest some improvements:
    1) The ability to save renaming schemes - eg "standard", "web"
    2) Character replacements - eg new filename = first 5 characters of old filename + "dog" + all characters after 16th character of old name
    3) Search and replace - eg replace "dog" with "cats"
    If any of these aren't clear, I'd happily elaborate.
    John

    I second the request for improvements in batch renaming. In my view the "standard" for this function is the Bulk Rename Utility (www.bulkrenameutility.co.uk) by Jim Willsher and Paolo Messina, if I were Adobe I would look at that feature set as the goal.

Maybe you are looking for

  • How to open JTree in browser?

    Hi Friends, 1)I have a tree which is displayed using swing ,If i clicks on the node of the tree i want to display some details in a browser.How can i do it? 2)Is it possible to display a tree created by JTree in a browser

  • Getting Service Error

    Hi all, I am trying to get the samples ( PIM, Hello world etc) to work but I am getting Service Error as a response to all the example apps. I have upgraded my wireless install to 9.0.2.8 as per a previous suggestion but with no success. Panama_sys l

  • P2V a 2008 R2 DC on Hyper-V 2012 R2 with VMM 2012 R2

    We are looking to use Hyper-V in one of our offices and i'm looking for the best way to move one of our physical DCs which is also a print server to a VM running on a Hyper-V cluster.  I would like to P2V this server because been the print server for

  • Can't make any purchase from the AppStore even if it is free ,

    Hey There Can't make any purchase from the AppStore even if it is free ,It always tells me error has occurred. This happens since I upgraded to Mavericks,, Could you please help

  • Question about Encapsulation

    I have two classes that have a parent-child relationship sort of. interface IProject{       void doIt(); class Project implements IProject{      List architectures;      public doIt(){ class Architecture {      Project project; }The question is how d