The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Invoke Perl function from Bash ? NewDeb Shell Programming and Scripting 1 11-13-2008 12:09 PM
Need help with changing bash to perl freak UNIX for Dummies Questions & Answers 3 07-01-2008 11:44 AM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 01:25 PM
bash awk codes to perl phamp008 Shell Programming and Scripting 1 03-15-2008 05:11 AM
bash to perl conversion thumper Shell Programming and Scripting 2 07-14-2006 04:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2009
kermit's Avatar
kermit kermit is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
Mixing Perl with Bash

I am fiddling with a little script that will issue a shutdown command if the temperature on the CPU goes above a certain level. I started writing the script in Bash, and then thought I would like to use Perl to extract the detailed bits, but I am not sure if this is really practical. Basically I want to parse the input a little better, but I am a bit of a novice at both Bash and Perl. I know how to extract what I want with Perl, but not so much with Bash. I know how to get the raw data with Bash, but I don't know how best to get that data to Perl, and then back as a variable to Bash so it can decide whether to leave the machine running, or issue a shutdown command. I wrote the first bit of the Bash script, which was relatively simple, but now I am at a standstill as I don't know how to bring Perl into the picture. Would my best bet be to write the 'raw data' to a file, and then call a separate Perl script, have it alter the file data as necessary, then read in the newly parsed data (in Bash) and act on that? Here is what I have gotten so far:


Code:
#!/bin/bash

cur_tmp= sensors | grep 'CPU Temp:' \
        | awk '{ print $3 }' \

  #2 (permalink)  
Old 01-03-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365

You can use shell parameter expansion to extract what you want. E.g.:


Code:
temp=$( sensors | grep 'CPU Temp:' )
temp=${temp##*/}


Last edited by Neo; 01-03-2009 at 11:46 PM.. Reason: Changed wording
  #3 (permalink)  
Old 01-04-2009
kermit's Avatar
kermit kermit is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
Quote:
Originally Posted by cfajohnson View Post

You can use shell parameter expansion to extract what you want. E.g.:


Code:
temp=$( sensors | grep 'CPU Temp:' )
temp=${temp##*/}

Thank you. I ended up doing the following (It is not the complete script, but the part I asked about works well.)


Code:
cur_tmp=$(sensors | grep 'CPU Temp:' | awk '{ print $3 }')
cur_tmp=${cur_tmp#+}
cur_tmp=${cur_tmp%°C}

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0