Wrapper script for image deployment - stdin/stdout - named pipes and the like


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wrapper script for image deployment - stdin/stdout - named pipes and the like
# 1  
Old 09-23-2008
Java Wrapper script for image deployment - stdin/stdout - named pipes and the like

Hi everyone, first post here.

Anyone who isn't interested in the background, press pagedown Smilie.

I sometimes need to make scripts for little things I need in the infrastructure at the company I work at. Currently I am trying to make a wrapper script for a proprietary image-deployment program. In this case RapiDeploy if anyone is curious.

Anyway, I am currently using the selfmade linux-executables created by this program for a custom-made recovery-cd solution I have currently based on SysrescCD 0.4.3 ( Yes I know it's old, but it works Smilie).

Anyway, the recovery-cd simply boots up and runs an autorun-script that probes a number of prospective /dev/cdroms for a file named recovery.exe and then executes it.

The self-extracting executable has an ncurse-ish (it may well be ncurses) interface that outputs as follows if the output is sent to a file(ugly sample, sorry):
Imaging NTFS from slot 1  Mode: Restore (/mnt/cdrom/recovery.exe)
 Elapsed: 8:47 Remaining: 15 minutes Thruput: 222 MB/min (30 Mbps)
 þþþþþþþþþþþþþþþþþþþþþþþþþþ(0~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(B 35%
 Imaging NTFS from slot 1 



The problem comes in when you want to be able to restore from CDs, or the image is too large for DVD, because the images have to be spread out. The images are named, recovery.exe, recovery.002, etc.

When a split image is executed, the program first starts imaging the contents of the first file, recovery.exe, and then asks for the path of .002.

When a user comfortable with the ins and outs of nix-terminals and rdeploy uses it, simply: Switching to another tty - umounting - inserting next cd - mounting - switch back and press enter to search again in the default path (cwd), works just great.

However, I would like to create a wrapper for this executable file, so that someone not so technically inclined may use it. Describing the general outline of my idea in "pseudo-code" below:


correctcd-device=$(__Code to find correct CD device here ( Already have this, ugly but functional))

./recovery.exe < /root/inputtempfile > /root/outputtempfile #
progress=$(cat /root/outputtempfile | sed 'arguments to find application progress % and filter the rubbish'
echo $progress #Or draw a rough progress-bar, prefferably but not necessarily
if/when/case/whatever is suitable - still sketching $(cat /root/outputtempfile | sed 'arguments to find application output')= "Please insert next CD"
(
umount /mnt/cdrom
eject /dev/$correctcd-device
echo "Please insert next disc and press Enter"
mount /dev/$correctcd-device /mnt/cdrom
echo "Character that equals ENTER" > /root/inputtempfile # This is to make rapideploy act as if someone had typed the ENTER-key, which makes it look again in the default path /mnt/cdrom
)
# Insert more code to make it handle the recovery finishing, initiating unmounting, eject and reboot.

I think you get the idea, the biggest problem for me is how to correctly handle input/output, which is the most important atm. The progress bar etc I guess i could grep my way to later on.

I have looked into and tested back and forth with temp files and mkfifo/named pipes etc without really succeeding at running the application hidden but connected in the way I wish.

This, to me, seems to be the key to all the rest.
Other info:
The livecd has got both sh, bash and zsh.
Kernel version: 2.6.23.01-fd11

Thanks in advance for all your constructive criticism and suggestions, pointers and clues, and even cut-and-paste working code most welcome :P

Regards,
Andreas Ericson

Last edited by andreas.ericson; 09-23-2008 at 11:30 AM..
# 2  
Old 09-23-2008
I'm not sure I understand "exactly" your problem with user input, but here is a "simple minded" first cut.

I would use

echo ="Please insert next CD"
Then I would insert a test loop here, to test every few seconds for the "new" CD and flash the message again if it wasn't there. When it is detected, the loop exits back to the script and continues with processing.


Or if you trust the user, a simple:

echo ="Please insert next CD and press enter when it is inserted"
read

construct would do. The problem here is that the script is on hold until the user remembers to press enter and pressing it before the CD is ready could cause problems depending on your code.

I will be gone for a week so I will not be able to discuss this further. Hope this helps and as they say "Have Fun"
# 3  
Old 09-23-2008
Thanks for your reply!

That would work excellently if the application doing the imaging was open source or my own application, problem is it is proprietary closed source.

Thus, I need to run it in the background and read its output to know when to prompt for a new cd, and then send input, keystrokes more specifically, to the program to tell it to continue.

Unless anyone has a better idea Smilie

Edit: In clarification:

I have been able to use mkfifo to redirect output to another shells input, for example. One thing I am unable to do however is sending a simple ENTER key-stroke.

Perhaps I am using the wrong tools to write to the input? I am using echo so far, searching for other methods...

Last edited by andreas.ericson; 09-24-2008 at 04:12 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

STDIN and STDOUT

Hallo, i have a script like: if ;then echo "OK" else echo "ERROR $2 is missing" fi; if ;then touch $2 fi; if ;then cat $1 | grep xy > $2 (1 Reply)
Discussion started by: eightball
1 Replies

2. Shell Programming and Scripting

can't close stdin/stdout in shell

#!/bin/sh exec 0</dev/null exec 1>/dev/null ls -l /proc/self/fd >&2 produces total 0 lr-x------ 1 tyler users 64 Feb 18 10:38 0 -> /proc/7886/fd lrwx------ 1 tyler users 64 Feb 18 10:38 1 -> /dev/pts/4 lrwx------ 1 tyler users 64 Feb 18 10:38 2 -> /dev/pts/4 I've verified the shell is... (10 Replies)
Discussion started by: Corona688
10 Replies

3. UNIX for Dummies Questions & Answers

Named Pipes

hi, i am working on a script for oracle export, m using a parameter file... i want to compress the dump file that is generated.. in my script following is the code i have written. i am not able to generata .gz file mknod /tmp/exp_tesd1_pipe p gzip -cNf... (4 Replies)
Discussion started by: saharookiedba
4 Replies

4. Programming

stdout/stdin + flushing buffers

Hi all I've run into a snag in a program of mine where part of what I entered in at the start of run-time, instead of the current value within printf() is being printed out. After failing with fflush() and setbuf(), I tried the following approach void BufferFlusher() { int in=0;... (9 Replies)
Discussion started by: JamesGoh
9 Replies

5. HP-UX

remove named pipes

Hi, Please help me on this. I am creating a named pipe in a kshell script. I am using mkfifo pipe_name command to create the pipe. I want to remove the named pipe after my work is completed. How can i do that. (8 Replies)
Discussion started by: chintapalli001
8 Replies

6. Shell Programming and Scripting

named pipes

How to have a conversation between 2 processes using named pipes? (5 Replies)
Discussion started by: kanchan_agr
5 Replies

7. UNIX for Advanced & Expert Users

tee into 2 named pipes

The following code does not work (zsh, Solaris), but works without the first line (files instead of pipes) :confused: mkfifo p1 p2 echo "Hello" | tee p1 > p2 & paste p1 p2 I would high appreciate any help to fix it. (9 Replies)
Discussion started by: zzol
9 Replies

8. Shell Programming and Scripting

FIFO named pipes

Hi...Can anyone please guide me on FIFO Pipes in UNIX.I have lerant things like creating fifo pipes,using them for reads and writes etc.I want to know what is the maximum amount of memory that such a pipe may have? Also can anyone guide me on where to get info on this topic from? (1 Reply)
Discussion started by: tej.buch
1 Replies

9. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

10. Shell Programming and Scripting

named pipes

Hi I am having trouble with a script to export individual schemas to tape from an oracle database. Basicaly I need to export each shema through a pipe with compression and store each shema name in a file with the relevant tape marker. (4 Replies)
Discussion started by: truma1
4 Replies
Login or Register to Ask a Question