Bash script to extract certain parts of an xml

Here is what i'm dealing with, i have 2 files, one xml file and one file containing certain class names from the first one, the point is to filter the xml file so the newly created file only contains the classes defined in the second or list file. So far i've come up with an idea but got stuck on the last step, hope someone is willing to point me in the right direction
The xml file is called description.xml and the list is list.txt
#!/bin/bash
# First i extract all the required class names and put in the missing parts
cat list.txt | awk '{print "<class name=\"" $1 "\">"}' > filter.txt
# Next i filter out all the line numbers of the required classes
grep -n -f filter.txt description.xml | cut -d: -f1 > names.txt
# Now i need to use something like awk '/NR=$n/,/^$/' so it filters
out the whole class definition using the line number as the starting
point and a newline as the ending of a class, and of course save it all
in a new xml but so far nothing i tried worked :)
The list file is one class name per line:
java/net/xyz
java/net/xzy
java/net/yxz
And a snippet from the description.xml:
<class name="java/net/xyz">
</class>
<class name="java/net/xzy">
</class>

Ahh I see what you're doing. That is a smart approach. I would have gone for a script that reads every line and extracts the java/net/xzy if it has one and grep -q it to the list.txt, and then maintain a variable that says whether it should print the class that gets set to false when </class> comes.
In this case it is a bit hard to use awk because you need to process the line numbers from a file and the data too, and line numbers aren't the easiest to work with.
But sed can do that easily
IFS="
for sedcmd in $(sed 's~$~,/^$/p~' numbers.txt); do sed -n "$sedcmd" xmlfile.xml; done
Last edited by Procyon (2009-04-14 00:49:41)

Similar Messages

  • Oracle script to extract SQL server data to XML/CSX file format

    HI,
    I have a requirement like-
    Create an Oracle script to Extract data from SQL Server to XML/CSV file format in File server (Oracle Server and File Server are in different boxes).
    Create an Oracle script to Retrieve data from the File Server, validate and load into the Oracle staging table
    Create an Oracle script to Push data from Oracle Staging table to native SQL Server table
    We may/may not be using the staging table
    Could anyone please respond immediately as it is urgent ?
    Thanks,
    Inbamalar

    user10594152 wrote:
    HI,
    I have a requirement like-
    Create an Oracle script to Extract data from SQL Server to XML/CSV file format in File server (Oracle Server and File Server are in different boxes).
    Create an Oracle script to Retrieve data from the File Server, validate and load into the Oracle staging table
    Create an Oracle script to Push data from Oracle Staging table to native SQL Server table
    We may/may not be using the staging table
    Could anyone please respond immediately as it is urgent ?
    Thanks,
    Inbamalar
    Urgent issues indicate a live/production system is having problems and a company is losing money, or customers are being prevented from using it.
    For urgent issues you should raise your issue with Oracle Support using your customer support identifier.
    The community forums are for non-urgent issues.  To suggest such issues are urgent is considered rude, as the people who help here are volunteers with their own jobs to do, so demanding their time for your "urgent" issue is not appropriate.  It also suggests that you think your issue is more important than other people's issues, so you are being rude to those people too.  Your issue is no more important than anyone elses.
    In relation to your question, you need to provide more information.
    Please read: Re: 2. How do I ask a question on the forums?
    When you refer to "SQL Server" are you referring to the Microsoft SQL Server product, or are you just referring to a physical server with your oracle database on it?

  • HT1338 hi, my firefox and safari are both having difficulty loading certain parts of web pages. previous to this my firefox would freeze and state that a script was not responding. i would stop the script and reload the page and everything would be fine.

    hi, my firefox and safari are both having difficulty loading certain parts of web pages. previous to this my firefox would freeze and state that a script was not responding. i would stop the script and reload the page and everything would be fine. now though the pages just load very very slowly or load leaving out certain pictures and video content. i've tried clearing my cache's and cookies, resetting my browser etc, but it seems like its a system issue as both safari and firefox are having issues. i've run Avast to screen for malware and it came up empty. any suggestions?

    10.4.8's been a pain for Networking... not sure of all the reasons though, or whether all the complaints might not be MS working around Bugs/Non-compliance, but at this point I think you should get Applejack...
    http://www.versiontracker.com/dyn/moreinfo/macosx/19596
    After installing, boot holding down CMD+s, then when the prompt shows, type in...
    applejack AUTO
    Then let it do all 5 of it's things.
    Fixes a lot of problems, and besides, if your Mac ever gets to the point it won't Boot... this is a life saver!
    After you run that... let's see where we are.
    BTW, several ISPs seem to have trouble with their DNS Servers lately, might try these insead...
    208.67.222.222
    208.67.220.220

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • Sending email using bash script

    Hello:
    I am working on writing a bash script to notify one or more users by email of certain events. Run from the Terminal command line, and having the script "echo" text of (what would be) a form letter with in-line variable expansion (i.e., ${VARIABLE}), all seems to work as anticipated. Eventually, I want cron to launch this shell script, and send an email to an "on-subnet" user (I have postfix enabled on my Mac, and there are multiple local user accounts).
    I found some stuff on the web about sending mail from bash scripts, and so I made a small little test script, that reads like this:
    #!/bin/bash
    VARIABLE[1]="The 12,345 quick brown foxes "
    VARIABLE[2]="jumped over the 67,890 lazy dogs."
    mail -s "a test email" jv << EOF
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EOF
    echo "script completed"
    It worked... almost... It sent a local email to my postfix mail account that read like this:
    This is a test:
    The 12,345 quick brown foxes
    jumped over the 67,890 lazy dogs.
    This is the last line of the test message.
    EOF
    echo "script completed"
    So, I have two questions. First, the easy one (I hope):
    How do I delimit the end of the text, that I want to be the message body of the email, from portions of the script that follow said email text?
    Next question is a little more involved. You know how, in Mail.app, if you go to Mail Preferences>Accounts>Account Information, you can put multiple email addresses, comma-delimited, in the "Email Address" field? So, if a person entered "[email protected], [email protected], [email protected]" in this field, then, even though (s)he may be at home, and using their home ISP's mail server, (s)he could send an email apparently from either their home, work, or school email address. Of course, the mail headers clearly would show it came from and through their home machine and home ISP, but it would be displayed in the recipient's Mail client viewer as having come from one of [email protected], [email protected], or [email protected].
    I'd like to do something similar here, whereby the email (that is being sent to one or more local users' postfix account on my computer) would apparently be sent from "watchdog@localhost" rather than from "jv@localhost" like it seems to do by default. Whatever account the script is run from (or presumbably, whose cron tab is launching the script) is what the "From" address is set to.
    I'd rather not create an additional mail account, because I am using Mac OS X built-in accounts for the postfix mailboxes (I don't want to have to maintain a plaintext username:password file in postfix, and I don't want to create an additional user account on the computer).
    So, is there a way to specify an alternate "From" username when invoking the mail -s ${SUBJECT} ${RECIPIENT} command in a bash script? Or is there a different, alternate mail command that will let me do so? (please include a description of syntax and how I'd package the above message text for the alternate method).
    Thanks in advance, all!

    Hi j.v.,
    The > after EOF is just a typo (or may be added by the Discussion ?) and you must delete it; other > are prompts from the interactive shell. Andy's post shows an interactive use of shell, not a shell script (note the shell prompt % in front of the commands). A typical use of here document may look like
    command <<ENDOFDATA
    ENDOFDATA
    There must be no spaces before and after ENDOFDATA. The word ENDOFDATA can be EOF or any other string which is guaranteed not to appear in the text (the .... in the example above).
    You can modify the From: header by using sendmail command (postfix has it as a compatibility interface):
    /usr/sbin/sendmail -t <<EndOfMessage
    Subject: test mail
    To: jv
    From: watchdog
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EndOfMessage
    There must be a blank line between the headers and the mail body.
    I assume that you send these mails only to users on your local Mac. Please do not send mails to remote users by using the sendmail command unless you know what you are doing completely.
    PowerMac G4   Mac OS X (10.4.5)  

  • Using Bash script to edit config file

    This is a really simple question, but given that I'm just learning Bash scripting and having this solved now would be really illustrative for me, I would really thank some help here.
    I'm using uzbl, and running Tor+Polipo. So, as you will see below in the tail of the config file, there is a line to redirect the requests of uzbl through Polipo.
    # === Post-load misc commands ================================================
    sync_spawn_exec @scripts_dir/load_cookies.sh
    sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
    # Set the "home" page.
    #set uri = https://duckduckgo.com
    # Local polipo proxy
    set proxy_url = http://127.0.0.1:8123
    # vim: set fdm=syntax:
    What I want to accomplish is to comment in/out that line with a key shortcut on Awesome. I've thought of doing 2 scripts to do so and using 2 differente key shortcuts, but I want to "toggle" the proxy redirection with only 1 shortcut. To do so, I suppose that the script should go something like:
    if
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    else
    if
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    fi
    fi
    I know little about sed, but I think is the tool for this job. The most intriging part to me is to ask sed to print the regular expression when it finds it in the config file, and use that as an input in the conditional statement.
    Well, this is a mess I have done here. Hope there is a simple answer to this.
    Thanks in advance.-

    You can do this with a single sed command:
    sed -i 's/^#set proxy_url/set proxy_url/;
    t end;
    s/^set proxy_url/#set proxy_url/;
    : end' config_file
    This edits the file in-place (-i) and first tries to replace the commented with the uncommented line. If that suceeds, sed jumps to the "end" label. If not, it tries to replace the uncommented with the commented line. Thus you don't have to include any logic about the current state: if the first substitution succeeds, the line was obviously commented, if not, it was uncommented, and the second substitution should succeed.
    Note that my knowledge of sed is very limited. There might be a simpler way to do this.
    EDIT: For the sake of example, here's how to do the same in bash using regular expressions. Note how this script needs to use a temporary file to simulate in-place editing, how it needs to process the file line by line manually, etc. All things that sed does out of the box...
    #!/bin/bash
    tmp=test.conf.tmp
    echo -n "" > "$tmp"
    while read line; do
    if [[ "$line" =~ ^#set\ proxy ]]; then
    echo "${line/\#/}" >> "$tmp"
    elif [[ "$line" =~ ^set\ proxy ]]; then
    echo "#$line" >> "$tmp"
    else
    echo "$line" >> "$tmp"
    fi
    done < test.conf
    mv test.conf.tmp test.conf
    To answer your original question, the line
    if [[ "$line" =~ ^#set\ proxy ]]; then
    reads: if the line begins with a "#", followed by "set proxy", then...
    Last edited by hbekel (2011-03-20 10:40:16)

  • HOW DO I  RUN A UNIX BASH SCRIPT FROM JAVA??

    HI. Here's a tricky little problem i have. There's a unix bash script that has some commands in it, that manipulate a file. It appends a certain string variable to a file called users. The users file is an ordinary text file.
    I know this script to work perfectly, when i invoke it like this directyl from the command line: ./addusers.sh
    or even: bash /downloads/selinux/policy/addusers.sh
    Now, i have a java program, and its meant to just execute that script. It doesnt throw any Exceptions at runtime. But when i look at the users file, and expect it to have an extra line that was the string variable, the file is UNTOUCHED!
    Again, direct command line invocation works, but not from java. Here's what my invocation from java looks like:
    Process p = Runtime.getRunTime().exec("bash downloads/selinux/policy/addusers.sh");
    The strange thing is, i tried a different bash command. I tried:
    Process p = Runtime.getRunTime().exec("mkdir /temporary");
    and this worked!
    so why not the other one??
    I cant figure it out.

    You say:
    bash /downloads/selinux/policy/addusers.sh
    And you say in Java:
    Process p = Runtime.getRunTime().exec("bash
    downloads/selinux/policy/addusers.sh");
    As if a leading / would be missing from the Java
    version...nyix says:>
    ...OK sorry about that. i DO have a / in front of the downloads.... section in the java method. So its:
    Process p = Runtime.getRunTime().
    exec("bash /downloads/selinux/policy/addusers.sh");
    HELP please?

  • Bash script to pseudo multithread a encode job lame

    Conceptually, I don't see why a bash script couldn't run x simultaneous lame mp3 encodes where x is the number of cores the user selects.  I just don't know how to go about doing it.  Would it make sense to read in all the .wav files to an array, then divide the array into x sub arrays and feed the work out or is there a more simplistic method?
    EDIT: I found this blog entry but I don't fully understand it. 
    Here is my adaptation of his code:
    #!/bin/bash
    # the number of cores you have on your system
    cores=4
    encode() {
    for file; do
    fileout=$(echo "$file" | sed s'/.wav//')
    lame -V 2 "$file" "$fileout".mp3; done
    export -f encode
    find . -name '*.wav' -print0 | xargs -0 -n 1 -P $cores bash -c 'encode "$@"' --
    Can someone explain to me what the last bit does: 'encode"$@"' --
    Last edited by graysky (2010-03-01 22:17:13)

    The last bit calls the encoide function, passing in all the arguments as past to it on stdin.
    'encode "$@"' calls encode and passes it its arguments (as passed to it from the find command).
    -- tells xargs that there are no more command line options, and to interpret anything "-" as part of the file names.
    man find and man xargs for more info.
    The "--" I'm not sure which man page it'll be in but I think it's a GNU thing?

  • Problem with "date -d" function in bash script. Leopard bug?

    I have this really nice rsync bash script that I use to make rotating snapshot backups of my different Ubuntu servers to a single backup server.
    I am now trying to use this same script on my Leopard machine, but it seems to have a serious problem with the following lines of code:
    lday=`date +'image-%Y-%m-%d-%H' -d '1 day ago'`
    lweek=`date +'image-%Y-%m-%d-%H' -d '1 week ago'`
    It generates the following error:
    date: illegal time format
    usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
    [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
    It's clear that it doesn't like the "-d '1 day ago'" part in my code.
    Is there a different way in Leopard to get yesterday's or last week's date in a bash script? Or is this a Leopard bug?
    Could someone please help me out? I've be trying to research this for the past 8 hours, but can't seem to find any solution to this problem.
    Thanks in advance.

    Is there a different way in Leopard to get yesterday's or last week's date in a bash script?
    date -v-1d
    date -v-7d

  • Solaris sends SIGKILL to bash script?

    I have this bash script that just loops forever (until stopped), it outputs data to files and runs various other commands to display information on the terminal. The problem I'm having is that solaris seems to send SIGKILL to this script after it's been running for a period of time. Typically a few hours. As far as I can tell there's doesn't appear to be anything obviously wrong with the script. Why would solaris send a SIGKILL?? I know it's a sigkill from the exit code 137.
    Anyone have any suggestions?? I'm running Solaris 8.
    Thanks

    No idea, it doesn't really make sense.
    You could check if there is anything in crontab or similar which kills processes of idle users, but thats a bit of a long-shoot.
    Make your script log to a file frequently, so you can figure out when to determine if its always around the same time, and in which part of the script.
    If Solaris would send it a kill signal it wouldn't be SIGKILL.
    .7/M.

  • How to use the image manipulation palette to extract a part of an image

    How to use the image manipulation palette to extract a part of an image?I have a parent image from which i need to extract a certain sub part.can somebody pls help me on how to use this particular tool?
    Thanks

    Use the above snippet. You might need to convert the Image Type you are using with picture functions. The above snippet will give you good idea on how to achieve what you intend to.
    -FraggerFox!
    Certified LabVIEW Architect, Certified TestStand Developer
    "What you think today is what you live tomorrow"

  • Unexpected token `(' in my bash script [Solved]

    I've been working on a bash script, and I'm trying to get it to move all directories that are not named certain names to another directory.
    EDIT: Fixed the thing papajoke pointed out
    #!/bin/bash
    mv ~/Downloads/!(folders|pics|docs|code|archives|vids|sounds)/ ~/Downloads/folders/
    The command from the script does what I want it to do when I run it from a terminal.
    It also works if I run the script as follows:
    source script.sh
    It doesn't work like this:
    bash script.sh
    I'm trying to get it to run when I login, and using the running the command with "source" in my MATE Startup Applications doesn't work.
    I'm new to bash scripting, any help would be much appreciated.  Thanks
    Last edited by physicsshark (2015-04-07 20:09:07)

    Trilby wrote:I've never seen that syntax
    You mean the pipes or the bang?
    $ touch a.gz b.gz c.txt
    $ ls !(*.gz)
    c.txt
    This works as an alias and from the comeliness commandline, but not in a script.
    $ ls -l ~/2
    total 16
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 a
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 b
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 c
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 d
    $ mv ~/2/!(a|b|c) ~/2/a
    $ ls -l ~/2
    total 12
    drwxr-xr-x 3 karol users 4096 Apr 7 03:14 a
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 b
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 c
    $ ls -l ~/2/a
    total 4
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 d
    Last edited by karol (2015-04-07 01:20:14)

  • Bash Scripting with Conky -- How to implement?

    Hey Folks, my first post here and I'm looking for a bit of help. I've created a bash script to work with conky in which its purpose is to change the color of the battery bar depending on current voltage.
    Here's the bash script:
    #!/bin/bash
    # Change Conky battery color depending on charge
    chrg=`cat /proc/acpi/battery/BAT1/state | grep "remaining capacity" |
    awk '{print $3 }'`
    echo $chrg
    if [ $chrg -lt "3499" ]; then
    ${color red}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    elif [ "$chrg" -lt "5100"]; then
    ${color orange}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    else ${color green}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    fi
    Essentially what it is supposed to do is grab and store the "remaining capacity" and if its lower than a certain point it changes color. What I'm having trouble with is actually implementing the colors into conky. Right now all it is doing is printing the charge as you can see. Any help would be appreciated. Thanks!

    I had this issue, took me three days to solve. Using if_match, put all your if_matches in a line, with each option having its color of choice, then put the bar, or % at the end.  You will need to make sure it is in sequential order so the color will not overlap the color you want for the state in the if_match. I know this is an old thread, I will edit my post when I get on my netbook with the code.
    I found this thread on a google search for bash and conky usages.
    [edit] here was my solution for the if_match using the battery.
    ${if_match ${battery_percent BAT1} <= 49}${color0}${endif}${if_match ${battery_percent BAT1} <= 20}${color9}${endif}${if_match ${battery_percent BAT1} >= 50}${color4}${endif}${battery BAT1} ${alignr}${battery_bar 6,160 BAT1}
    I have my colors set yellow for 49% and below, red 20% and lower, and last green for 50% and higher. Essentially this will pick yellow for under 49% and the if_match for red under 20%, the red will override the yellow, this is why order is important.
    Remember this is all in one line, now there are cleaner ways of setting this up using lua. That is something I am still working on.
    Last edited by mrknify (2014-03-05 17:09:59)

  • Get initial directories in bash script

    I have a variable TEST in a bash script
    TEST=/ABCService/ZeroComposite/deploy/sca_XYZ.jar
    I want to parse this TEST variable to have a new variable COMPOSITE_DIR with value "/ABCService/ZeroComposite". Looks pretty simple but I am on it for about 3 hours now. Exhausted all option with regex, dirname, basename etc. There has to be a simple way to do this.
    Thanks

    Giving up after only 3 hours already?
    How about the following:
    var=$(echo $TEST | rev | cut -d'/' -f3- | rev)
    echo $var
    /ABCService/ZeroComposite
    The cut command allows to specify a character delimiter that acts like a field separator. The parameter -f3- would normally extract the string starting at field number 3 and all remaining fields. The trick is to reverse the order of the string so that the cut command will cut from the end to the beginning, instead from the beginning to the end, and then reverse the string again to get the result.

  • [solved] Segmentation fault with bash script

    I have a bash script that checks if it has to do something, if not it sleeps 15 secs and checks again. It works great except that after ~6hrs of just checking and sleeping it seg faults. I upped the stack limit with ulimit -s and it goes ~12hrs before it seg faults. I have a similar script that I have been using for ages that works for 24hrs no problem and I can't pinpoint where the problem is.
    The check it does is to see if a file exists, if it's empty and if not, read the first line of a file and do some date comparisons. It doesn't matter if the file is empty or not the seg fault always happens.
    Here's the seg fault causing script - it starts at the bottom
    #!/bin/bash
    # User defines
    declare -i DVB_DEVICE_NUM="0"
    declare CHANNELS_CONF="${HOME}/Mychannels.conf"
    declare SAVE_FOLDER="${HOME}/TV/tele"
    declare SCHED_FILE="$HOME/.sched-tv"
    declare ZAP_COMMAND="tzap"
    declare -i SLEEP=15
    # Program defines
    declare -i DAY="0"
    declare -i START="0"
    declare -i FINISH="0"
    declare CHAN="0"
    declare NAME="0"
    declare -i MINUTES="0"
    declare -i REC_START="0"
    declare -i REC_HOURS="0"
    declare -i REC_MINS="0"
    declare -i howlong="0"
    declare -i PIDOF_AZAP=0
    declare -i PIDOF_CAT=0
    red='\033[1;31m'
    green='\033[1;32m'
    yell='\033[1;33m'
    cyan='\033[1;36m'
    white='\033[1;37m'
    reset='\033[0m'
    function remove_entry {
    if [ "$NAME" == "" ]; then
    sed "/$DAY $START $FINISH $CHAN/d" $SCHED_FILE > /tmp/dummy
    else
    sed "/$DAY $START $FINISH $CHAN $NAME/d" $SCHED_FILE > /tmp/dummy
    fi
    mv /tmp/dummy $SCHED_FILE
    function record_entry {
    ${ZAP_COMMAND} -a ${DVB_DEVICE_NUM} -f ${DVB_DEVICE_NUM} -d ${DVB_DEVICE_NUM} \
    -c $CHANNELS_CONF -r ${CHAN} >/dev/null 2>&1 &
    PIDOF_AZAP=$!
    if [ "$PIDOF_AZAP" == "" ]; then
    printf "$red\tError starting ${ZAP_COMMAND}.\n\tFAILED: $CHAN $START\n"
    remove_entry
    exit 1
    fi
    printf "$green\tSET CHANNEL$cyan ${CHAN}\n"
    REC_MINS=$((${START}%100))
    REC_HOURS=0
    MINUTES=0
    REC_START=$(($START-$REC_MINS))
    while [ $((${REC_START}+${REC_HOURS}+${REC_MINS})) -lt $FINISH ]; do
    ((REC_MINS++))
    ((MINUTES++))
    if [ ${REC_MINS} -ge 60 ]; then
    REC_MINS=0
    ((REC_HOURS+=100))
    fi
    done
    if [ "$NAME" == "" ]; then
    declare FILE_NAME="${SAVE_FOLDER}/TV-`date +%Y%m%d-%H%M`-ch.${CHAN}-${MINUTES}.min.mpg"
    else
    declare FILE_NAME="${SAVE_FOLDER}/TV-${NAME}-${MINUTES}.min.mpg"
    fi
    dd if=/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} \
    of=${FILE_NAME} conv=noerror &
    PIDOF_CAT=$!
    if (( ${PIDOF_CAT} == 0 )); then
    printf "$red\tError Starting Recording.\n\t/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} Unavailable\n"
    kill ${PIDOF_AZAP}
    remove_entry
    exit 1
    fi
    printf "$yell\tRECORDING TO :$cyan ${FILE_NAME}\n"
    sleep ${MINUTES}m
    kill ${PIDOF_CAT} && wait ${PIDOF_CAT} 2> /dev/null
    # pkill $ZAP_COMMAND # && wait ${PIDOF_AZAP} 2> /dev/null
    kill ${PIDOF_AZAP} && wait ${PIDOF_AZAP} 2> /dev/null
    printf "$yell\tFINISHED REC :$cyan ${FILE_NAME}\n$reset"
    remove_entry
    waiting 1
    function check_action {
    [ -e "$SCHED_FILE" ] || waiting $SLEEP
    [ "`cat $SCHED_FILE`" == "" ] && waiting $SLEEP
    DAY="0"; START="0"; FINISH="0"; CHAN="0"; NAME="0"
    TODAY=`date +%Y%m%d`
    NOW=`date +%k%M`
    while read -r DAY START FINISH CHAN NAME; do
    #printf "$DAY $START $FINISH $CHAN $NAME\n"
    break
    done < $SCHED_FILE
    if [ $DAY == $TODAY ] && [ $START -lt $NOW ]; then
    printf "$red\tOld Entry : Removing $CHAN $START\n"
    remove_entry
    waiting 1
    fi
    if [ $DAY == $TODAY ] && [ $START == $NOW ]; then
    record_entry
    else
    waiting $SLEEP
    fi
    function waiting {
    howlong=$1
    sleep $howlong && check_action
    check_action
    exit 0
    And the script that has been working fine 24hrs at a time
    #!/bin/bash
    echo alarm uses a twelve hour clock
    echo Type the time for the alarm to sound as 00-00-?m
    echo e.g. 05-35-pm for 5:35pm :: 05-35-am for 5:35am
    read TIME
    function play {
    A="$(date +%I-%M-%P)"
    if [ $A = $TIME ]; then
    for i in {1..10}; do
    $(aplay -c 1 /home/$USER/alarm/chime.wav); done
    exit
    else
    wait
    fi
    function wait {
    sleep 15 && play
    play
    I was hoping to have this script idling away in screen with rtorrent, always ready to do something if need be but that's not going to happen unless I can get a clue on what part of the script I need to change to not hit any limits. My websearches are failing me on this...
    Last edited by moetunes (2012-06-24 21:41:52)

    Thanks falconindy. I changed to using a while loop.
    #!/bin/bash
    set -o nounset
    shopt -s huponexit
    # User defines
    declare -i DVB_DEVICE_NUM="0"
    declare CHANNELS_CONF="${HOME}/Mychannels.conf"
    declare SAVE_FOLDER="${HOME}/TV/tele"
    declare SCHED_FILE="$HOME/.sched-tv"
    declare ZAP_COMMAND="tzap"
    declare -i SLEEP=15
    # Program defines
    declare -i DAY="0"
    declare -i START="0"
    declare -i FINISH="0"
    declare CHAN="0"
    declare NAME="0"
    declare -i MINUTES="0"
    declare -i REC_START="0"
    declare -i REC_HOURS="0"
    declare -i REC_MINS="0"
    declare -i howlong=$SLEEP
    declare -i PIDOF_AZAP=0
    declare -i PIDOF_CAT=0
    red='\033[1;31m'
    green='\033[1;32m'
    yell='\033[1;33m'
    cyan='\033[1;36m'
    white='\033[1;37m'
    reset='\033[0m'
    function remove_entry {
    if [ "$NAME" == "" ]; then
    sed "/$DAY $START $FINISH $CHAN/d" $SCHED_FILE > /tmp/dummy
    else
    sed "/$DAY $START $FINISH $CHAN $NAME/d" $SCHED_FILE > /tmp/dummy
    fi
    mv /tmp/dummy $SCHED_FILE
    function record_entry {
    ${ZAP_COMMAND} -a ${DVB_DEVICE_NUM} -f ${DVB_DEVICE_NUM} -d ${DVB_DEVICE_NUM} \
    -c $CHANNELS_CONF -r ${CHAN} >/dev/null 2>&1 &
    PIDOF_AZAP=$!
    if [ "$PIDOF_AZAP" == "" ]; then
    printf "$red\tError starting ${ZAP_COMMAND}.\n\tFAILED: $CHAN $START\n"
    remove_entry
    exit 1
    fi
    printf "$green\tSET CHANNEL$cyan ${CHAN}\n"
    REC_MINS=$((${START}%100))
    REC_HOURS=0
    MINUTES=0
    REC_START=$(($START-$REC_MINS))
    while [ $((${REC_START}+${REC_HOURS}+${REC_MINS})) -lt $FINISH ]; do
    ((REC_MINS++))
    ((MINUTES++))
    if [ ${REC_MINS} -ge 60 ]; then
    REC_MINS=0
    ((REC_HOURS+=100))
    fi
    done
    if [ "$NAME" == "" ]; then
    declare FILE_NAME="${SAVE_FOLDER}/TV-`date +%Y%m%d-%H%M`-ch.${CHAN}-${MINUTES}.min.mpg"
    else
    declare FILE_NAME="${SAVE_FOLDER}/TV-${NAME}-${MINUTES}.min.mpg"
    fi
    dd if=/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} \
    of=${FILE_NAME} conv=noerror &
    PIDOF_CAT=$!
    if (( ${PIDOF_CAT} == 0 )); then
    printf "$red\tError Starting Recording.\n\t/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} Unavailable\n"
    kill ${PIDOF_AZAP}
    remove_entry
    exit 1
    fi
    printf "$yell\tRECORDING TO :$cyan ${FILE_NAME}\n"
    sleep ${MINUTES}m
    kill ${PIDOF_CAT} && wait ${PIDOF_CAT} 2> /dev/null
    # pkill $ZAP_COMMAND # && wait ${PIDOF_AZAP} 2> /dev/null
    kill ${PIDOF_AZAP} && wait ${PIDOF_AZAP} 2> /dev/null
    printf "$yell\tFINISHED REC :$cyan ${FILE_NAME}\n$reset"
    remove_entry
    while true; do
    sleep $howlong
    howlong=$SLEEP
    [ -e "$SCHED_FILE" ] || continue
    [ "`cat $SCHED_FILE`" == "" ] && continue
    TODAY=`date +%Y%m%d`
    NOW=`date +%k%M`
    while read -r DAY START FINISH CHAN NAME; do
    #printf "$DAY $START $FINISH $CHAN $NAME\n"
    break
    done < $SCHED_FILE
    if [ $DAY == $TODAY ] && [ $START -lt $NOW ]; then
    printf "$red\tOld Entry : Removing $CHAN $START\n"
    remove_entry
    howlong=1
    continue
    fi
    if [ $DAY == $TODAY ] && [ $START == $NOW ]; then
    record_entry
    fi
    done
    exit 0
    I think that should be ok now.

Maybe you are looking for

  • Is it possible to add a user or license for just one app?

    I have a complete Adobe Creative Cloud license. Is it possible to add a user or license for just one app? What are the monthly costs?

  • Is there any way to get Session

    Hi All, Is there any way of getting the HttpSession object reference using sessionid? thanks in advance Raghu

  • Profit center: Actual line items (KE5Z)

    Hello All, When I try to Display the actual line items through KE5Z, the system is throwing the message as"Table contains data records with no profit center" (KM 138), when I checked in the table GLPCA there are two records available without profit c

  • Mail always on top

    Every time I unlock my iBook, after using the screen lock, the Mail application appears on top of all other applications. I can't find any setting which would cause this to happen, and am curious if this is a bug or a "feature".

  • Can my mac be a carrier of PC viruses?

    Is it possible for a mac to be a "carrier" of PC viruses, and infect PC's with said viruses if files are shared via flashdrive, etc. between the computers? If so, are there any antivirus scans I can do that will search my mac for these viruses?