Mkbootfs writing to stdout in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mkbootfs writing to stdout in bash script
# 8  
Old 04-17-2013
That is very odd. If that really is the code, there's no reason at all for it to do that... I suspect your version ended up a little different somehow, but would need to use strace or something to tell what it's really doing.

The trick with nohup may also help narrow it down.

It's also possible there's more than one mkbootfs, and due to PATH differences your shell runs one and your script runs the other!
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 04-17-2013
Sure, I use that source to compile it along cyanogenmod source
No error about the called binary as I use full path to call it, not in PATH var

Here's the output from nohup you asked for

Shell:
Code:
#!/bin/bash
nohup /root/Desktop/build_cm10/android_cm-10.1/system/out/host/linux-x86/bin/mkbootfs /root/Desktop/build_cm10/android_cm-10.1/system/out/target/product/n7100/recovery/root > /root/Desktop/build_cm10/android_cm-10.1/system/out/target/product/n7100/ramdisk-recovery.cpio

Code:
nohup: ignoring input and redirecting stderr to stdout


It created the cpio file with correct content Smilie

While nohup works while not my redirection usual rules?
# 10  
Old 04-17-2013
It is a mystery. It really shouldn't do that.

Show me the exact line that didn't work please -- unabridged, no substitutions, exactly as you had it. The entire script, even. There may be context missing, something before that line which changed the meaning of your redirection.
This User Gave Thanks to Corona688 For This Post:
# 11  
Old 04-17-2013
Well,
Thanks to you, I could repeat and reproduce the exact issue cause. Here's what I messed with:

In fact, after only removing nohup from exactly above script, my script still works perfectly

Now, the below script will trigger the issue

Code:
#!/bin/bash
CMD_LINE1="/root/Desktop/build_cm10/android_cm-10.1/system/out/host/linux-x86/bin/mkbootfs /root/Desktop/build_cm10/android_cm-10.1/system/out/target/product/n7100/recovery/root > /root/Desktop/build_cm10/android_cm-10.1/system/out/target/product/n7100/ramdisk-recovery.cpio"

$CMD_LINE1

So, it seems the cause is putting the command line into a variable and trying to run it that way, which causes output to stdout
Should I have used exec or similar to do it that way?
# 12  
Old 04-17-2013
You can see what is happening, why it does not work, if you use "set -x" at the top of the shell script.

Unless there is some good reason (can't think of any), do not try putting an entire command line, including redirection, into a variable.

I would suggest the following, to improve readability, to get rid of extremely long line which is maybe causing confusion:
Code:
dir=/root/Desktop/build_cm10/android_cm-10.1/system/out
   cmd=$dir/host/linux-x86/bin/mkbootfs
 input=$dir/target/product/n7100/recovery/root
output=$dir/target/product/n7100/ramdisk-recovery.cpio
$cmd $input > $output

This User Gave Thanks to hanson44 For This Post:
# 13  
Old 04-18-2013
Quote:
Originally Posted by hanson44
You can see what is happening, why it does not work, if you use "set -x" at the top of the shell script.

Unless there is some good reason (can't think of any), do not try putting an entire command line, including redirection, into a variable.

I would suggest the following, to improve readability, to get rid of extremely long line which is maybe causing confusion:
Code:
dir=/root/Desktop/build_cm10/android_cm-10.1/system/out
   cmd=$dir/host/linux-x86/bin/mkbootfs
 input=$dir/target/product/n7100/recovery/root
output=$dir/target/product/n7100/ramdisk-recovery.cpio
$cmd $input > $output

I will try it and report back, thanks
# 14  
Old 04-18-2013
Yes, "set -x" can be pretty useful. It can create a lot of output, which can be difficult to wade through. But for the most part "set -x" shows what is going on, what the shell "sees".
This User Gave Thanks to hanson44 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] Performance question - Script to STDOUT

Hello Coders Some time ago i was asking about python and bash performances, and i was told i could post the regarding code, and someone would kindly help to make it faster (if possible). If you have noted, i'm on the way to finalize, finish, stable TUI - Text(ual) User Interface. It is a... (6 Replies)
Discussion started by: sea
6 Replies

2. Shell Programming and Scripting

Writing Hbase and pig scripts in the bash script file

Hi, I have a script file where i'm validatig the input file and storing the validated records on HDFS. I wanted to load data from HDFS to HBASE using pig script. So for that i have created a HBASE table and written pig script to load data from HDFS to HBASE which is working fine. Now i wanted... (0 Replies)
Discussion started by: shree11
0 Replies

3. Shell Programming and Scripting

Writing hive scripts in bash script file

Hi, I wanted to load data from HDFS to HIVE by writing bash script. Description: I have written a bash script to validate the data and loaded validated data from local file system to HDFS. Now in the same bash script i wanted to load the data from HDFS to HIVE. How can i do it ? Also how tyhe... (2 Replies)
Discussion started by: shree11
2 Replies

4. Shell Programming and Scripting

Question about writing a bash script

Hello, I want to write a bash script to delete the content after '#'. However, if '#' appears in a string with "", ignore this. For example, input file: test #delete "test #not delete" Output file: test "test #not delete" Does anyone know how to write this script? Thanks (1 Reply)
Discussion started by: jeffwang66
1 Replies

5. Shell Programming and Scripting

Writing a bash script using host

Im trying to write a script using the host command but its not working properly. I cant understand what Im doing wrong. When I use it at the command prompt, it works fine. But its being used actually in the script, it says its not found: 2 SERVFAIL. Can anyone help me? Here's what I have so far: no... (6 Replies)
Discussion started by: relsha
6 Replies

6. Homework & Coursework Questions

brand new user!.. Lost on BASH script writing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have just gotten into writing bash scripts for a class, part of the assignment is to read and be able to tell... (4 Replies)
Discussion started by: Byrang
4 Replies

7. Shell Programming and Scripting

Help with writing simple bash script

I want to write a bash script to: 1. Send an email from localhost to an external gmail account. (gmail then automatically forwards the message back to a pop account on the same server. 2. Script waits 3 minutes then checks to see if the email arrived, and if not, it sends an email to... (9 Replies)
Discussion started by: sallyanne
9 Replies

8. Shell Programming and Scripting

bash, help with stdout manipulation.

Hey all, Im kind of lost on how to do what I want so I figured I would ask. I want to pipe STDOUT of an app to a log file, but I want to prepend each line of that output with the date and time. Im drawing a complete blank on how to do this?? Any ideas? i.e. output is currently this:... (9 Replies)
Discussion started by: trey85stang
9 Replies

9. Shell Programming and Scripting

Writing Bash script

Could anyone help me to Write a script in BASH Shell to determine the percentage of system disk space you are using. (1 Reply)
Discussion started by: boris
1 Replies

10. Shell Programming and Scripting

Problems writing bash script to unzip files

I'm getting the following errors when I try to write a script to unzip some zip files. When I use the free trial copy of the commerical winzip program, however, they work fine. When I use -l or -t on unzip it indicates no errors. When I use the -o switch interactively from the bash command line it... (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question