How to syndicate XML in a shell script? [SOLVED]

I am trying to write a script which will read http://www.weather.gov/data/current_obs/KLEX.xml and extract the temperature (<temp_c>), pressure (<pressure_mb>), and humidity (<relative_humidity>). Can anyone help me? I suspect I need to use wget...
#!/bin/bash
case "$1" in
t) echo "12 °C" ;;
p) echo "1014.7 mb" ;;
h) echo "51%" ;;
esac
Last edited by tony5429 (2008-03-13 01:29:09)

#!/bin/sh
cd /tmp
wget -nc http://www.weather.gov/data/current_obs/KLEX.xml 2> /dev/null
grep -e "<temp_c>" -e "<pressure_mb>" -e "<relative_humidity>" KLEX.xml | \
sed 's/^[ \t]*//' | sed -e 's/<[^>]*>//g'
rm -f KLEX.xml
The only problem is if the values change order you will have no idea which line corresponds to which value. You could run 3 grep/sed instances matching each one individually though if you want. Or you can use something fancier but I'd need to know how you intend to use these values.
Edit: There are a few other safety checks I ignored, like did wget succeed, but you can add that in easily if you feel like it.
Last edited by Zepp (2008-03-12 21:41:58)

Similar Messages

  • How to execute sql-queries through shell scripting in linux?

    How to execute sql-queries through shell scripting in linux?

    http://www.oracle.com/technology/pub/articles/saternos_scripting.html
    Two simple examples:
    #!/usr/bin/env bash
    set_orafra () {
       orafra=`echo 'set heading off
       select name from v$recovery_file_dest;
       exit' | sqlplus -s / as sysdba`
    set_orafra
    echo $orafra
    #!/usr/bin/env bash
    export ORACLE_SID=instance_name
    export ORACLE_HOME=/path_to_oracle_home_directory
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    export PATH=/$ORACLE_HOME/bin/$PATH
    $ORACLE_HOME/bin/sqlplus -s <<EOF
    connect scott/tiger@my_instance_name
    INSERT INTO table VALUES (sysdate);
    exit
    EOFEdited by: Markus Waldorf on Sep 17, 2010 12:19 AM

  • Tips for parsing xml in a shell script?

    Hello,
    I'm writing a shell script to extract info from an xml file to create various text files that share data in the form of custom entities declared at the top of the document (product id, name, version, copyright date, etc.). So far I'm using xmllint which is working well. I'm extracting text for my project files using xmllint --shell:
    <pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #222; background: #eee; line-height: normal">echo cat lls_cd_product/plist | xmllint --noent --shell xyz.xml | sed -e '1d; $d'</pre>
    This is working well, but --shell mode adds an extra line to the beginning and end which I let sed cleanup, but then I need to strip the enclosing tags as well.
    Xmllint does a good job of filling in my entities with the exception of MacRoman bullet characters that I've entered as &#165;. These are just converted to the same entity in hex, &#xA5;. I suppose I can replace those with sed, but that's starting to feel kludgey.
    I'm beginning to wonder if there may be a better way to do this. I'm not very familiar with XSL, but I am considering ramping up on that.
    Any suggestions would be welcome.
    Cole

    etresoft wrote:
    It may be a few hours before I get time to work on it.
    Or not.
    Here is your XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <info>
    <ver>2.1.1</ver>
    <tag>abc</tag>
    <name>Product Name</name>
    <filename>productname</filename>
    <copyright>2008</copyright>
    </info>
    This generates the cd product file:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"
    doctype-system="http://www.apple.com/DTDs/PropertyList-1.0.dtd"
    doctype-public="-//Apple Computer//DTD PLIST 1.0//EN"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <plist version="1.0">
    <dict>
    <key>hfs-openfolder</key>
    <string>.</string>
    <key>hfs-volume-name</key>
    <string><xsl:value-of select="name"/></string>
    <key>hide-hfs</key>
    <string>./{Norton,*.txt,*.exe,.inf}</string>
    <key>hide-iso</key>
    <string>./{PDS,*Rename,readme,.Volume*,Norton*,*icns,Run*.app,Icon*,Desktop*,TheFolder}</string>
    <key>hide-joliet</key>
    <string>./{PDS,*Rename,readme,.Volume*,Norton*,*icns,Run*.app,Icon*,Desktop*,TheFolder}</string>
    <key>iso-volume-name</key>
    <string><xsl:value-of select="tag"/></string>
    <key>joliet-volume-name</key>
    <string><xsl:value-of select="name"/></string>
    </dict>
    </plist>
    </xsl:template>
    </xsl:stylesheet>
    and this generates the Mac read me file in XML:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <!-- You don't have to deal with these entities anymore. You should be
    able to save this xsl file in UTF-8 format and just type in the
    bullets. But the entities work too. -->
    <readme_mac><xsl:value-of select="concat(name, ' ', ver)"/>
    Copyright <xsl:value-of select="copyright"/>, Laureate Learning Systems¨, Inc.
    Minimum System Requirements:
    ¥ 300 MHz or faster PowerPC, Intel or better CPU
    ¥ Mac OS 8.1 or later, including any Mac OS X
    ¥ 64 MB available RAM
    ¥ 60 MB available disk space
    </readme_mac>
    </xsl:template>
    </xsl:stylesheet>
    This one will output the readme in HTML:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="html" indent="yes" version="4.0" encoding="UTF-8"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <!-- You don't have to deal with these entities anymore. You should be
    able to save this xsl file in UTF-8 format and just type in the
    bullets. But the entities work too. -->
    <html>
    <head>
    <title><xsl:value-of select="concat(name, ' ', ver)"/></title>
    </head>
    <body>
    <xsl:value-of select="concat(name, ' ', ver)"/>
    Copyright <xsl:value-of select="copyright"/>, Laureate Learning Systems¨, Inc.
    Minimum System Requirements:
    300 MHz or faster PowerPC, Intel or better CPU
    Mac OS 8.1 or later, including any Mac OS X
    64 MB available RAM
    60 MB available disk space
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Yes. I do enjoy XSL quite a bit

  • How to avoid password prompt in shell script for zip password protection

    Hi
    I am trying to set password protection to my oracle database export backup. Once the backup completed, it should compress with a password protection. Thats the plan. Initialy we were using the gzip for the compression. Then realized that there is no password protection for the gzip. Started using zip option. I tried using
    zip -P <password> filename
    But it was throwing below error.
    -bash-3.2$ zip -P expreports REPORTS_2013FEB14.dmp
    zip warning: missing end signature--probably not a zip file (did you
    zip warning: remember to use binary mode when you transferred it?)
    zip warning: (if you are trying to read a damaged archive try -F)
    zip error: Zip file structure invalid (REPORTS_2013FEB14.dmp)
    Not quite sure why.
    Then I used zip -e REPORTS_2013FEB14.dmp.zip REPORTS_2013FEB14.dmp
    But this prompting for the password. As I am trying to put the command in the script. It will be tough if it prompts for the password.
    I would like to know how to avoid the password prompting by saving somewhere or how the code should be written. Tried using expect feature of shell script. Below was the code I tried. It didnt work.
    [oracle@SF40V6636 test]$ cat repexp.sh
    zip -e REPORTS_imp.log.zip REPORTS_imp.log
    expect "Enter password:"
    send "imprep"
    expect "Verify password:"
    send "imprep"
    So please help in avoiding this password prompt or let me know how to change the code.
    Thanks
    SHIYAS M

    How about using gpg and adding a secret key to the requirement of a password? No one should be able to decrypt your file, not by knowing only the password.
    1. Generate a public and private key pair:
    $ gpg --gen-key
    When it shows "We need to generate a lot of random bytes…" open another terminal session and type "dd if=/dev/sda of=/dev/null" to create traffic. When the public and secret key created and signed you can Ctrl-C the dd command.
    To see what you have created:
    $ gpg --list-keys
    2. Encrypt and gzip your stuff:
    $ tar zcf stuff.tgz file_or_folder
    $ gpg recipient "Some Name" encrypt stuff.tgz
    $ rm -f stuff.tgz
    3. Decrypt and extract the archive:
    $ gpg batch yes --passphrase "password" -d stuff.tgz.gpg > stuff.tgz
    $ tar zxvf stuff.tgz
    Again, knowing the password alone will not let anybody decrypt your stuff.

  • How to use encoded password in shell script ?

    Hi everybody,
    For make a load file in oracle table, I'm using a LKM File to Oracle updatding with a sqlldr (shell script).
    My problem is very simple : For security reason in this shell-script , I don't want to see in clear the password of the Oracle user for database connection. Is it possible and how do it ?
    Thanks in advance

    Hi-
    Yes it is possible by the way of KM custamization, You need to modify LKM call sqlldr via jython step to pass the user info and password as variable instead of ODI method. Try this command in your KM step:
    userid=#GLOBAL.user/#GLOBAL.psw
    Hope this will work for you.
    Thanks,
    Saravanan Rajavel

  • How to prepare for Converting UNIX shell scripts to PL/SQL

    Hi All
    I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
    what are the options PL/SQL is having to best do that.
    I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
    to prepare myself to do it the best way. What are the concepts i have to be familiar with.
    Many Thanks
    MJ

    Just how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
    If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
    There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
    Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
    In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
    On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL.

  • How to replace a word thr shell script

    Hi,
    I need a shell script which should read a file(a.txt)
    and need to update the same file( means only replace a word with another one in the same file)
    my unix version is SunOS and i am using ksh
    could you pls provide me some better way.
    My failured trails are as below
    suppose a.txt file having data like,
    column1 column2 column3
    data1 data2 data3
    and my script is,
    #!/usr/bin/ksh
    patha=/tmp
    filea=a.txt
    sed '/column2/s//column4/g' $patha/$filea > $patha/$filea
    And also pls provide how to add data(data into new line) into file(a.txt)
    Thanks in advance.

    This is an Oracle SQL and PL/SQL forum.
    If you want to learn how to write unix shell scripts I suggest you search the internet for a suitable unix forum.

  • How to call a procedure from  Shell Script

    Friends,
    How can i call a procedure from a shell script ? If any one know the answer , let me know immediately .
    Thanks in advance .
    Chakks

    We connect using SQLPlus commands on the Unix server:-
    Our code block is below:- We've got DBMS_OUTPUT in the procedure, hence the spooling. You don't need all this, but you do need the sqlplus directory, etc... in your profile.
    sqlplus -s <<EOF > ${CREATE_LOG_FLE}
    $UserName/$Password@$SID
    SET SERVEROUTPUT ON SIZE 1000000;
    spool ${CREATE_LOG_FLE}
    EXECUTE $STORED_PROC(${Months}, ${DeleteRecords});
    EOF
    Hope that helps

  • How do i print parameters in shell script through java

    Hi,
    I am sorry if have posted this query in wrong thread!!!
    How do i print the parameter in shell script which are passed from java programm?
    i have tried in different ways.. but the actual param value is not printing when i execute the java programm
    java code is here
    import java.io.IOException;
    public class TestShell {
          * @param args
    public static void main(String[] args) {
             String inputFilePath=args[0];
              String inputFileName=args[1];
              String outputFileName=args[2];
              String outputFilePath=args[3];
              Runtime r = Runtime.getRuntime();
              String[] cmdArray = new String[]{"Test.sh",inputFilePath, inputFileName, outputFileName, outputFilePath};
              try {
                   r.exec(cmdArray);
                   System.out.println("Test.sh executed successfully.");
              } catch (IOException e) {
                   e.printStackTrace();
    }I need a shell script to print paramenters (inputFilePath, inputFileName, outputFileName, outputFilePath)
    Thanks,
    Jasmin

    user13836688 wrote:
    But my code is something look like thisWell unless I've completely lost my marbles (possible) or Java Runtime.exec() does something I've never heard of, I can't even see how that will execute. For a start, assignments in the Bourne shell take the form ofinfile = $inputFilename;orinfile = "inputFilename";not what you've got; and the first form would only work if you've set the appropriate environment variables.
    Are you sure you're not confusing this with a Javascript script?
    Winston
    Edited by: YoungWinston on Apr 18, 2011 12:51 PM
    And BTW, you don't need to put ';' at the end of each statement, unless there's more than one on a line.
    Edited by: YoungWinston on Apr 18, 2011 12:54 PM
    BTW2: 'printf "%d", inpath' also looks very dodgy, since 'inpath' is unlikely to be a number (in fact, it's unlikely to be anything).
    I think you might want to get a book on scripting.

  • How To Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • How to prevent Automator's "run shell script" to create fully decomposed forms of my strings ?

    I am using Automator's "run shell script" and I am seeing that it outputs fully decomposed forms of my strings.
    For example, when I set the action to "echo été" in a service (with "Replace selected text" activated) and run that into a Textwrangler window, I'll get fully decomposed forms that Textwrangler won't understand. But when I simply type that command into Terminal, I get my string in composed form.
    The problem is not the display issue, but the fact that if I want to run grep for example in "run shell script", I will not be able to find the proper strings since the forms are different.

    Originally I was using $@ to parse a string and get the result pasted by the service. That was a while ago. There, I noticed that some Japanese characters were messed up. Basically all the kana characters that come with voicing markers like が-ga (instead of か-ka) etc. I did not have the time to pursue that issue though.
    Then, last night, I found that a colleague of mine had tried to use $@ to feed to a local dictionary application called ding (http://ftp.tu-chemnitz.de/pub/Local/urz/ding/). His problem was with characters that had umlauts. After verifying how he wrote his action I remembered that I had similar issues with Japanese.
    Basically his command was "/path/to/ding $@"
    That's supposed to use the selected string as an argument to pass to ding, which will launch a Wish application where the string is used as the searched item.
    From Terminal, that works a treat. But the exact same line in Automator (with input as argument, not as stdin) messed the composition and the resulting string was not recognized by ding as a match to what it was supposed to match.
    So, I tried a few things to get to the core of the issue and found that a simple "echo [accented characters]" was enough to reproduce the difference in string handling between Automator and Terminal. That difference is also reproduced on a number of person's machines.
    I have a number of services that basically revolve on "run shell script" actions and involve 3rd party application outputs, preference files etc. so it would not be convenient to show that to you.
    I have sent a mail about this issue to the automator list yesterday too:
    http://lists.apple.com/archives/Automator-users/2011/Jun/msg00004.html

  • How to truncate text in a shell script? [SOLVED]

    Here is my shell script...
    #!/bin/bash
    case "$1" in
    artist) dcop amarok player artist ;;
    title) dcop amarok player title ;;
    esac
    I want it to send the artist and title truncated if they are more than 20 characters and with a little '...' ellipsis at the end. Can anyone help me?
    Last edited by tony5429 (2008-03-12 13:28:24)

    This might be a starting point, even though I don't know the answer: http://developer.apple.com/documentatio … 03521-SW16 (gosh what a long URL)
    edit
    wow, I was slow
    Last edited by finferflu (2008-03-11 20:52:38)

  • How to Call Multiple Sessions through Shell scripting

    Dear Members,
    I have a scenario where I load data into target table from 20 different source tables.
    For this I have written three procedures where there exists an bulk insert executed on a same table in every procedure. Now I have to call these procedures simultaneously so that
    all three bulk loads are executed at once in different sessions.
    For this I have to write a shell script which opens 3 different sessions and execute all these packages at once.
    Can you guide me through.

    When you call sqlplus in your shell script, put a & at the end so that it runs the SQL scripts in the background. For instance:
    #!/bin/bash
    ...oracle home stuff
    $ORACLE_HOME/bin/sqlplus user/pass @script.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script2.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script3.sql &

  • How get parent path of running shell script

    Friends,
    I have a bush shell that location is /u01/test/oracle/codes/jobs/test.sh . I run below command in shell  get a shell scripts parents path.
    SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})) .
    But return  script location as /u01/test/oracle/codes/jobs.
    However, I want to return value as  /u01/test/oracle/codes   for variale.
    Any ideal
    Thanks

    How do you run or invoke the shell script?

  • How to detect a system crash (shell script)

    what is the easiest way to find out if the system has previously crashed or been powered off without a clean shutdown?
    i am looking for a way to be used in a unix shell script. is there e.g. a specific text i can look for in a specific logfile?
    a panic.log might not be enough because in case of power failure the system will not have time to write to that logfile.
    any help is greatly appreciated.

    The shutdown codes are not documented anywhere that I know of. I've seen these mentioned, but I don't know whether they're all accurate.
    -128: Battery or UPS dead (?)
    -62: PMU did not detect heartbeat (PPC Xserve)
    -60: Thermal (?)
       0: Low power
       3: Forced shutdown
       5: User requested restart or shutdown

Maybe you are looking for

  • Getting a error while deleting a personalized column in customer standard page.

    Hi, I have added a column through personalization in standard customer page. The personalization was working fine in the standard pag and I can able to see the column in the account section. But when I deleted the column which I had added through per

  • JDBC receiver adapter - stored procedure response

    I am on PI 7.11 and have the following scenario: RFC->PI->JDBC whereby the JDBC receiver access an Oracle db (unsure of that version) using a stored procedure "GET_ICBC_ID". My issue is that I never seem to have any data back in PI on the JDBC respon

  • MAJOR bug in iPhoto 11

    Running Mavericks and when I select the SHARE button in iPhoto 11 and select photos and then select to send with Messages, the application crashes and I have to force quit and re-opening iPhoto crashes when opening images and the images never leave m

  • Duplicates in my i-tunes library

    I seem to have got myself in a right mess - I store my music on an external hard drive that I don't always have attached to the Laptop. Occasionally I've downloaded tunes from I-tunes store when the hard drive is not attached....so then I had music o

  • [Solved] Can't Build qBittorrent

    Hello all, On a fresh system running on [testing], I can't build qBittorrent from the AUR (https://aur.archlinux.org/packages/qbittorrent/). I made sure all dependencies are met, but every time I try to build the package I get the same error: torrent