Errors running perl statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Errors running perl statement
# 1  
Old 06-11-2018
Errors running perl statement

When I run this

Code:
#!/bin/bash
Block count:              421958912
Reserved block count:     4219589
perl -e "printf(\"%.1lf%%\n\", ($Reserved block count * 100.0 ) / $Block count);"

I get these error messages. Can someone please help me?

Code:
andyk_~/Downloads$ Show_Percent_Reserved_Blocks.sh
/home/andy/bin/Show_Percent_Reserved_Blocks.sh: line 2: Block: command not found
/home/andy/bin/Show_Percent_Reserved_Blocks.sh: line 3: Reserved: command not found
syntax error at -e line 1, near "/ )"
Execution of -e aborted due to compilation errors.


Last edited by rbatte1; 06-12-2018 at 07:50 AM.. Reason: Change ICODE to CODE tags
# 2  
Old 06-12-2018
You are trying to execute every line in your script. Are you trying to assign the values to variables and then use that in the perl command?

Perhaps this would be better:-
Code:
#!/bin/bash
Block_count=421958912
Reserved_block_count=4219589

perl -e "printf(\"%.1lf%%\n\", ($Reserved_block_count * 100.0 ) / $Block_count);"

Note that the variable names do not include spaces. The underscore is permitted, but a hyphen or full stop are not.


Does this help?
Robin
# 3  
Old 06-12-2018
Your script will not work because block count and reserved block count are not in the script themselves.

Another bash script created another script with Block count: and Reserved block count: in them.

Here is that script.

Code:
cd /home/andy/Downloads/
echo xxxx | sudo -S tune2fs -l /dev/sda1 > list_tune.txt
# looks for block count and IS case insensitive
#
echo "#!/bin/bash" > Show_Percent_Reserved_Blocks.sh
grep -i "block count" list_tune.txt >>Show_Percent_Reserved_Blocks.sh
echo 'perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"' >>Show_Percent_Reserved_Blocks.shecho xxx |sudo -S chmod +x Show_Percent_Reserved_Blocks.sh

---------- Post updated at 08:15 AM ---------- Previous update was at 07:59 AM ----------

I see my problem.

I need to execute the perl script outside of a bash script.

Which is another step that I want to avoid.

Last edited by rbatte1; 06-12-2018 at 10:48 AM.. Reason: Changed ICODE to CODE tags
# 4  
Old 06-12-2018
Would you not be better with something else then, such as:-
Code:
#!/bin/bash

read a b block_count < <(grep -i "block count" list_tune.txt | grep -iv reserved)
read a b reserved_block_count < <(grep -i "reserved block count" list_tune.txt)

echo "\$block_count=\"$block_count\""
echo "\$reserved_block_count=\"$reserved_block_count\""
echo

perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"

Does that help a bit? This tries to read your input file and assign the variables before calling the perl command in a single script without trying to automate a code-writer/runner, which are notoriously difficult to assure.



Robin
# 5  
Old 06-12-2018
Thanks Robin for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Invalid option errors running shell script

The script below fails with the following error messages: gzip: invalid option -- 'w' Try `gzip --help' for more information. mysqldump: Got errno 32 on write cp: invalid option -- 'w' Try `cp --help' for more information. rm: invalid option -- 'w' Try `rm --help' for more information. ... (1 Reply)
Discussion started by: ANNACTION
1 Replies

2. Shell Programming and Scripting

Running a function from a case statement

Hi, I have the below script that should take the command line option and run the desired script on another server. Only it doesn't seem to run the function, infact it just returns back to the command line. case $1 in 1) msgbacklog() ;; 2) jobstatus() ;; ... (10 Replies)
Discussion started by: chris01010
10 Replies

3. Shell Programming and Scripting

Command not found errors when running csh script

I am trying to find the number of files whose name starts with uni. Below is the code but it is giving error. :confused: #!/bin/csh FILES_NAME ='files_list'; FILE_NAME_PATTERN = 'uni*'; NO_OF_FILES; ls -l $FILE_NAME_PATTERN > $FILES_NAME ; NO_OF_FILES = `wc -l $FILES_NAME`; echo... (3 Replies)
Discussion started by: hiten.r.chauhan
3 Replies

4. Shell Programming and Scripting

Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly? I have no problem getting the results if the command is properly executed. Ex. my @result = `dir`; foreach my $line (@result) { print "Result = $line";... (2 Replies)
Discussion started by: kooshi
2 Replies

5. Shell Programming and Scripting

PERL Syntax Errors

Hi, I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors. The actual command in the program (which is within a case structure) is given below # This gives the actual count of inquires from a log file (It works fine when I type this on the... (2 Replies)
Discussion started by: nurani
2 Replies

6. Shell Programming and Scripting

surpressing errors while running script

I have written shell script to find out pairsuspends in our environment.But when i run the script iam getting an error for the Pair which are not active.Below are the error am getting pairvolchk -g up1012 -I11 pairvolchk : execution error. pairvolchk: Unmatched CTGID within the group Refer... (3 Replies)
Discussion started by: zeebala1981
3 Replies

7. Shell Programming and Scripting

Compilation errors in running configure script

Hi all, I tried to cross compile Ghostscript-8.54 source. I am getting some errors during cross compilation. I have pasted the errors below. CC=arm-unknown-linux-gnu-gcc LD=arm-unknown-linux-gnu-ld ./configure --host=i686-pc-linux-gnu --target=arm-unknown-linux-gnu --without-x && make ... (2 Replies)
Discussion started by: siva4ever
2 Replies

8. Shell Programming and Scripting

running if statement on command line

Hi, is it possible to run an if statement from the command line? I am doing this # service postgresql status; if ] ; then awk '{print ""$2""}' /root/file.txt > But it throws me into a different mode ie the > then I have to do a ctrl+c. I want to do it this way because I will be... (2 Replies)
Discussion started by: borderblaster
2 Replies

9. Programming

Request help to debug errors while running in 'C'

I run, 2 'C' Files, gapw.c and getkey.c, but I get the following errors :- I) $ gcc gapw.c gapw.c: In function `main': gapw.c:96: warning: cast to pointer from integer of different size /tmp/cck4I8mW.o(.text+0x227): In function `main': : undefined reference to `getprofilestring'... (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

errors when running a cron job

I am running some shell scripts through a foll cron job, the script works fine and there are no errors in the log file but I receive the following error in mail for the jobs: stty: no such device or address What does the above error indicate, here is the cron job: 0 22 * * 0... (2 Replies)
Discussion started by: knarayan
2 Replies
Login or Register to Ask a Question