PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > reproduce "head -c" behaviour with dd
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

reproduce "head -c" behaviour with dd

Réponse
 
LinkBack Outils de la discussion
Vieux 05/12/2006, 15h45   #1
igeeo76@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut reproduce "head -c" behaviour with dd

Hi,

I use the following code to extract an archive and a gzip from an
auto-extractible shell script.

#! /bin/sh

#-- extract binaries from $0
byte_val=`expr $FILEBYTE + 1`
tail +${byte_val}c ${CURRENTPWD}/${progname} >binaries.out 2>$NUL
[ $? -eq 0 -a -f binaries.out ] || { NO; EXIT
$BINARIES_EXTRACTION_FAILED; }

#-- extract archive for binaries.out
byte_val=`expr $GZIPBYTE + 1`
tail +${byte_val}c binaries.out >$tgzarchive 2>$NUL
[ $? -eq 0 -a -f "$tgzarchive" ] || { NO; EXIT
$BINARIES_EXTRACTION_FAILED; }

#-- extract gzip for binaries.out
head -c +$GZIPBYTE binaries.out >gzip 2>$NUL
[ $? -eq 0 -a -f gzip ] || { NO; EXIT $BINARIES_EXTRACTION_FAILED; }

The problem is that the script need to be portable on Linux and most of
Unix flavor (HP-UX, AIX, SCO, Solaris, UnixWare) and "head -c" is not
supported everywhere (not on SCO, UnixWare, Solaris).

Is it possible to reproduce the head -c behaviour with dd command (or
with another unix commands ?)

TIA and regards,

Geoffrey Kretz

  Réponse avec citation
Vieux 05/12/2006, 16h51   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: reproduce "head -c" behaviour with dd

igeeo76@gmail.com wrote:
> Hi,
>
> I use the following code to extract an archive and a gzip from an
> auto-extractible shell script.
>
> #! /bin/sh
>
> #-- extract binaries from $0
> byte_val=`expr $FILEBYTE + 1`
> tail +${byte_val}c ${CURRENTPWD}/${progname} >binaries.out 2>$NUL
> [ $? -eq 0 -a -f binaries.out ] || { NO; EXIT
> $BINARIES_EXTRACTION_FAILED; }
>
> #-- extract archive for binaries.out
> byte_val=`expr $GZIPBYTE + 1`
> tail +${byte_val}c binaries.out >$tgzarchive 2>$NUL
> [ $? -eq 0 -a -f "$tgzarchive" ] || { NO; EXIT
> $BINARIES_EXTRACTION_FAILED; }
>
> #-- extract gzip for binaries.out
> head -c +$GZIPBYTE binaries.out >gzip 2>$NUL
> [ $? -eq 0 -a -f gzip ] || { NO; EXIT $BINARIES_EXTRACTION_FAILED; }
>
> The problem is that the script need to be portable on Linux and most of
> Unix flavor (HP-UX, AIX, SCO, Solaris, UnixWare) and "head -c" is not
> supported everywhere (not on SCO, UnixWare, Solaris).
>
> Is it possible to reproduce the head -c behaviour with dd command (or
> with another unix commands ?)


Yes. Have you read tha man page of dd? (see "bs=..." and "count=...").

Janis

>
> TIA and regards,
>
> Geoffrey Kretz
>

  Réponse avec citation
Vieux 05/12/2006, 17h23   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: reproduce "head -c" behaviour with dd

On 5 Dec 2006 07:45:37 -0800, igeeo76@gmail.com
<igeeo76@gmail.com> wrote:
> Hi,
>
> I use the following code to extract an archive and a gzip from an
> auto-extractible shell script.
>
> #! /bin/sh
>
> #-- extract binaries from $0
> byte_val=`expr $FILEBYTE + 1`
> tail +${byte_val}c ${CURRENTPWD}/${progname} >binaries.out 2>$NUL
> [ $? -eq 0 -a -f binaries.out ] || { NO; EXIT
> $BINARIES_EXTRACTION_FAILED; }
>
> #-- extract archive for binaries.out
> byte_val=`expr $GZIPBYTE + 1`
> tail +${byte_val}c binaries.out >$tgzarchive 2>$NUL
> [ $? -eq 0 -a -f "$tgzarchive" ] || { NO; EXIT
> $BINARIES_EXTRACTION_FAILED; }
>
> #-- extract gzip for binaries.out
> head -c +$GZIPBYTE binaries.out >gzip 2>$NUL
> [ $? -eq 0 -a -f gzip ] || { NO; EXIT $BINARIES_EXTRACTION_FAILED; }
>
> The problem is that the script need to be portable on Linux and most of
> Unix flavor (HP-UX, AIX, SCO, Solaris, UnixWare) and "head -c" is not
> supported everywhere (not on SCO, UnixWare, Solaris).
>
> Is it possible to reproduce the head -c behaviour with dd command (or
> with another unix commands ?)
>

dd bs=$GZIPBYTE count=1 if=binaries.out of=gzip
For very large files you might need to make bs <= system RAM and
count=$((GZIPBYTE / bs))


--
When a girl marries she exchanges the attentions of many men for the
inattentions of one.
-- Helen Rowland
  Réponse avec citation
Vieux 06/12/2006, 09h48   #4
igeeo76@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: reproduce "head -c" behaviour with dd

> dd bs=$GZIPBYTE count=1 if=binaries.out of=gzip
> For very large files you might need to make bs <= system RAM and
> count=$((GZIPBYTE / bs))
>
>
> --
> When a girl marries she exchanges the attentions of many men for the
> inattentions of one.
> -- Helen Rowland


Ok, thanks a lot. And as it doesn't use -skip, I guess that this
command is portable ?

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10690 seconds with 12 queries