Mixing Perl with Bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mixing Perl with Bash
# 1  
Old 01-03-2009
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  
Old 01-03-2009

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  
Old 01-04-2009
Quote:
Originally Posted by cfajohnson

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}

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

New to bash and perl scripting

How can we do submenu and show on the bottom how i can send back to main menu (1 Reply)
Discussion started by: ramindia
1 Replies

2. Shell Programming and Scripting

Perl command in bash

I have the below perl script that runs (I think): 'C:\Users\cmccabe\Desktop\annovar\matrix.pl' < "${id}".txt.hg19_multianno.txt > "L:\NGS\3_BUSINESS\Matrix\Torrent\matrix_${id}.txt" The problem is I get an error that the ${id}.txt does not exist. I have tried "${id}.txt as well. ... (42 Replies)
Discussion started by: cmccabe
42 Replies

3. Shell Programming and Scripting

perl limitations vs. bash?

I've building a bunch of bash scripts, and am thinking about "converting" to perl, and have a couple questions first: 1. Is there anything bash will do that perl won't? 2. How steep is the learning curve? 3. If perl's more powerful, why? 4. I've built a small app in python, which seemed nice,... (18 Replies)
Discussion started by: unclecameron
18 Replies

4. Programming

Mixing code in C and Perl

Hi there, if you want to write an application partly in C and partly in Perl and have a final executable binary is it possible to do so. If yes, how ? My motivation for asking this question is that there are certain tasks that are so tedious to write in C while it can be taken care of in Perl... (2 Replies)
Discussion started by: jad
2 Replies

5. Shell Programming and Scripting

***convert from perl to bash***

can any body translate the follwing script into one that works in bash? #!/usr/bin/perl # classify_books.pl my $csv_file = shift; my %categories = ( 'childrens' => 'childrens_books.txt', 'horror' => 'horror_books.txt', 'sports ' =>... (3 Replies)
Discussion started by: ferrycorsten73
3 Replies

6. UNIX for Dummies Questions & Answers

Need help with changing bash to perl

Hi guys, I am converting a bash script to perl. I need lots of help and pointers on how to make the script work. Any help would be greatly appreciated. Here is what I have: #!/usr/bin/perl #Decrypt Files $dir = "/usr/bin/gpg; opendir(PGP_DIR, $dir) || die "can't opendir $dir: $!";... (3 Replies)
Discussion started by: freak
3 Replies

7. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question