Visit Our UNIX and Linux User Community

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
# 1  
Old 04-16-2013
Mkbootfs writing to stdout in bash script


I need to automate some repacking tasks of a boot image for Android
When in command line, I can use this command:

mkbootfs /path/to/root > /path/to/ramdisk-recovery.cpio;

However, if I try to run the command from a shell script under Ubuntu, it fails and outputs to stdout instead of the specified ramdisk-recovery.cpio file.

I tried to pipe it using :
mkbootfs /path/to/root | cpio > /path/to/ramdisk-recovery.cpio;
# or
mkbootfs /path/to/root | cpio -o > /path/to/ramdisk-recovery.cpio;

but it fails also when in a bash script

I tried to redirect stdout using &> in different combinations, but I am still filling my screen while the ramdisk-recovery.cpio is not written

Anone knows how to correctly redirect the output for such programs? I found no manual/help for the mkbootfs binary
# 2  
Old 04-16-2013
cpio -O outputfilename

writes cpio output to a file, is that what you want? Seems like it.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 04-16-2013
Well, I can do it easily using find . | cpio ...

However, I was a bit confused to not be able to use mkbootfs in a shell script while it works in cmd line

By the way, after further looking, mkbootfs is just a cpio variant, so should not be piped to cpio anyway

So, let's see it as a general question: is there any workaround to such binaries that once in a shell script, write to stdout? And why does the piping fails in this case?
# 4  
Old 04-16-2013
Well, you weren't doing the same thing in terminal, you were doing command > file

In the script, you change it to command | cpio > file

Is cpio really needed here when it wasn't needed in the terminal? cpio reads filenames, but if mkbootfs doesn't print filenames, piping it into cpio makes no sense.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-16-2013
If you read well my first post you'll see that I did:
1- run this from command line in terminal: works perfect
mkbootfs /path/to/root > /path/to/ramdisk-recovery.cpio

2- put same line in shell script: it fails writing to stdout instead of the file

After that, I tried many piping tricks without success, even to gzip or using &>
mkbootfs /path/to/root | gzip > /path/to/ramdisk-recovery.gz

I attach the binary so that you can test

use as follow:
argument 1 is any folder, argument 2 is the path to the output cpio file it creates from your folder
mkbootfs /path/to/any_folder > /path/to/your_folder.cpio

Actually, I fixed my issue by using cpio instead of mkbootfs in my shell script.

However. I am still curious as to why I cannot redirect output from that binary
# 6  
Old 04-17-2013
Originally Posted by Phil3759
If you read well my first post you'll see that I did:
1- run this from command line in terminal: works perfect
mkbootfs /path/to/root > /path/to/ramdisk-recovery.cpio

2- put same line in shell script: it fails writing to stdout instead of the file
Well, stdout is the file, by definition, so it can't be writing to stdout... Try running nohup mkbootfs ... and seeing if the output ends up in nohup.out.

Without knowing the code of mkbootfs it's hard to say for sure -- it's not a standard command, I can't test it myself here. But it's possible for a program to tell if it has a terminal or not and act different accordingly.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 04-17-2013
Thank you for the support

Well, the source is here:

I "quickly" followed the source and I see no terminal check code
Also, the portion of code I noted where it writes:
fwrite(data, datasize, 1, stdout);

This is compatible with the cmd command syntax:
mkbootfs /path/to/root > /path/to/ramdisk-recovery.cpio

That is output redirected to a file with >

Now, I tried all redirection possibilities from this manual:
Advanced Bash Shell Scripting Guide - I/O Redirection
but none will work when this binary is run from a shell script instead of cmd line Smilie

As I said, I fixed my script using cpio instead, but just out of curiosity wanted to learn more about this issue

Previous Thread | Next Thread
Test Your Knowledge in Computers #736
Difficulty: Medium
In 1982, Commodore introduced the Commodore 64 as the successor to the VIC-20.
True or False?

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

Featured Tech Videos