jarjar
jarjar

Reputation: 29

Script don't extract tar

I have this script shell, it extract and install libpcap library

#!/bin/sh
PATH=/usr/src
wget=/usr/bin/wget
tar=/bin/tar

echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf libpcap-1.3.0.tar.gz
cd libpcap-1.3.0
./configure --prefix=/usr
make && make install

When I execute it , I have this error

tar (child): gzip: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
/bin/tar: Child returned status 2
/bin/tar: Error is not recoverable: exiting now
./install.sh: 14: cd: can't cd to libpcap-1.3.0

Upvotes: 0

Views: 2333

Answers (3)

Yannoff
Yannoff

Reputation: 374

When dealing with gzipped tar, you should explicitly pass the option -z, so your code should be something like:

$tar -xzvf libpcap-1.3.0.tar.gz

Upvotes: 0

Kannan Mohan
Kannan Mohan

Reputation: 1840

Incase if you want /usr/src added to PATH variable then the better approach will be as

PATH="$PATH:/usr/src"

To make your script run from any directory path use a separate variable which holds the absolute path of the source file path like file_path variable which is used in the below script.

#!/bin/sh
PATH="$PATH:/usr/src"
wget=/usr/bin/wget
tar=/bin/tar
file_path="/path/to/source-files"

echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf $file_path/libpcap-1.3.0.tar.gz
cd $file_path/libpcap-1.3.0
./configure --prefix=/usr
make && make install

Upvotes: 0

William Pursell
William Pursell

Reputation: 212198

You've changed PATH to /usr/src so when tar tries to exec gzip, it cannot find it because it only looks in /usr/src. You'll need to add the location of gzip to PATH (and the location of every tool that the configure script is going to call, as well as make), or call it explicitly instead of letting tar call it, or (best choice), don't modify PATH. If you insist on changing PATH, try PATH=/usr/src:/usr/sbin:/usr/bin:/sbin:/bin or PATH=/usr/src:$PATH, but really it's best to leave it alone and really odd to put a directory named src into it.

Upvotes: 2

Related Questions