Script don't extract tar - linux

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

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.

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

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

Related

"No such file or directory" while in link path

When compiling, I always place the build in a separate directory. For example:
mkdir build
cd ./build
(cd ..; ./bootstrap)
../configure
make
Since I have plenty of RAM the aim is to compile on a TMPFS.
The script gets the name of the project, uses it for the name for the directory created in $XDG_RUNTIME_DIR/build and finally links it.
# setup-build.sh
#!/usr/bin/bash
set -e
my_project_name=$(basename $(pwd))
my_project_build_dir="$XDG_RUNTIME_DIR/build/$my_project_name"
mkdir -p $my_project_build_dir
ln -s "$my_project_build_dir" "$(pwd)/build"
The script runs without a problem. But, when I do cd ./build; ../configure it returns an error: bash: ../configure: No such file or directory. The file most certainly does exist, but Bash can't find it!
I altered the script to this:
#!/usr/bin/bash
set -e
my_project_src_dir="$(pwd)"
my_project_name="$(basename $(pwd))"
my_project_build_dir="$XDG_RUNTIME_DIR/build/$my_project_name"
mkdir -p "$my_project_build_dir"
ln -s "$my_project_build_dir" "$(pwd)/build"
cd "$my_project_build_dir"
echo "$my_project_src_dir" > "./project-src-dir.txt"
To compile I have to type cd ./build; $(cat ./project-src-dir.txt)/configure; make. This causes Bash complete to partial break, though. As in I can't TAB complete file names from $my_project_src_dir with this method, but TAB completion for arguments works fine. Ifautoconf is needed: (cd $(cat ./project-src-dir.txt); ./bootstrap). If anyone has any other ideas I would still prefer to be able to just do ../configure, although this will have to do for now.
Edit: Had to change my_project_name="$(basename '$my_project_src_dir') to my_project_name="$(basename $(pwd))" as it was taking '$my_project_src_dir' literally.

Files with Hyphen at Beginning of Name

I have a bunch of files such as this --4gqARaEJE_0.000.wav.gz. How do I decompress them? Executing tar -xz --4gqARaEJE_0.000.wav.gz returns the error tar: unrecognized option '--4gqARaEJE_0.000.wav.gz'. Gzip returns the same error. I take it the hyphens are causing the error, but don't know the workaround.
I tried changing the file names to remove the hyphens, but that gives the same error. I also tried \ prior to the file name, but no luck there either. How do you handle this kind of thing?
I've tried a small example on my server.
With wget https://sourceforge.net/projects/od1n/files/samples.tar.gz/download I've downloaded a random sample file and saved it. File name was download initially.
I tried this:
root#server [~/stackoverflow]# mv download --download.tar.gz
mv: unrecognized option '--download.tar.gz'
Try `mv --help' for more information.
As expected, it didn't work but adding a -- did help.
root#server [~/stackoverflow]# mv -- download --download.tar.gz
root#server [~/stackoverflow]# ls
./ ../ --download.tar.gz
Now our file name is --download.tar.gz, to extract it I used following command.
tar -xvzf -- --download.tar.gz
This still fails.
tar: unrecognized option '--download.tar.gz'
However specifiying folder location did work as intended.
root#server [~/stackoverflow]# tar -xvzf ./--download.tar.gz
samples/
samples/modifiedSheppLogan_256x256.smp
samples/fmri_64x64.smp
samples/qualityPhantom_64x64.smp
samples/brain_64x64.smp
samples/brain_64x64x5.smp
samples/qualityPhantom_64x64x5.smp
samples/modifiedSheppLogan_64x64.smp
samples/brain_256x256.smp
samples/qualityPhantom_256x256.smp
samples/brain_128x128x5.smp
samples/fmri_128x128.smp
samples/modifiedSheppLogan_128x128.smp
samples/qualityPhantom_128x128x5.smp
samples/brain_256x256x5.smp
samples/point_spread_function.smp
samples/qualityPhantom_256x256x5.smp
samples/brain_128x128.smp
samples/qualityPhantom_128x128.smp
samples/frequency_dist.smp
root#server [~/stackoverflow]# ls
./ ../ --download.tar.gz samples/
In your case file might've been corrupted or the extension could be wrong.

Which tar options do I need to install node from binary on linux?

Background
I downloaded binary for linux 64-bit and I was following several tutorials, each with similar options:
tar -C /usr/local --strip-components 1 -xzf /path/to/node.tar.gz
I always get this error:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
I've googled and it seems I have manually specified gzip file format via one of these switches. File is actually tar.xz, not tar.gz. It was probably tar.gz in older versions.
I wonder what do all of these options mean and which one's I need?
Is there an auto-detect format option?
This is what running info tar said:
-C, --directory DIR
change to directory DIR
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
-x, --extract, --get
extract files from an archive
-z, --gzip, --gunzip --ungzip
-f, --file ARCHIVE
use archive file or device ARCHIVE
Questions
I don't understand options -f, --strip-components.
-f - What else can it be but a file? What is "device archive"?
--strip-components - What does --strip-components 1 exactly do here?
I don't see any numbers in the file.
Please provide example of filename which would be affected by --strip-components and explain how.
And what's the idea with installing nodejs on linux?
Just unzip to /usr/local or what else needs to be done?
First, tar is "smart" enough to detect the compression method used in an archive so it isn't necessary to specify -z or -j.
-f - What else can it be but a file? What is "device archive"?
A device archive could be a tape archive attached to your machine in /dev/your_tar
--strip-components - What does --strip-components 1 exactly do
tar xfz /var/www/site/site.gz --strip-components=2
will create /var/site.

cygwin extracting to another directory

I have a file, in Windows, called php_0.27.tar.gz and want to extract it to C:\Program Files\PHP\script through Cygwin using this command:
tar -xf php_0.27.tar.gz -C /Program Files/PHP/script
But I got an error saying:
tar: Files: Not found in archive
I tried this command too:
tar -xf php_.tar.gz --directory /Program Files/PHP/script
But I got an other error saying:
tar: php_0.27.tar.gz: Cannot open: No such file or directory
So I tried:
tar -xf php_.tar.gz --directory C:/Program Files/PHP/script
But I failed and now I am stuck. I need help
The space in the directory name Program Files is the source of the error ; putting the whole path to directory between quotes like this "C:/Program Files/PHP/script" solve the problem

How tar xvfz works in cygwin?

I tried tar with xvfz and -xvfc both didn't work in Cygwin on Windows.
$ tar xvfz sshpass-1.0.5.tar.gz
tar (child): sshpass-1.0.5.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Here cmd tar with '-'
$ tar -xvfz sshpass-1.0.5.tar.gz
tar: z: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Question :
1 . How does tar works with - or without _ ?
Please suggest to execute tar -xvfz sshpass-1.0.5.tar.gz.
tar has 3 types of syntax (according to this ):
long options (--file)
short options (-f)
old options (f)
For the old option syntax, all the letters must follow "tar" and must all fall into a single clump with no spaces. The order of the letters doesn't really matter, so long as the arguments to those letters follow the same order after the clump of options.
This old way of writing tar options can surprise even experienced users. For example, the two commands:
# tar cfz sshpass-1.0.5.tar.gz file
# tar -cfz sshpass-1.0.5.tar.gz file
are quite different. The first example uses ‘sshpass-1.0.5.tar.gz’ as the value for option ‘f’ and recognizes the option ‘z’. The second example, however, uses ‘z’ as the value for option ‘f’ — probably not what was intended.
Old options are kept for compatibility with old versions of tar.
The command with a '-' is equivalent to
tar -czf sshpass-1.0.5.tar.gz file
tar -cf sshpass-1.0.5.tar.gz -z file
tar cf sshpass-1.0.5.tar.gz -z file
Got it, there was a typo error for in file name, corrected and ran. it worked.
$ tar xvfz sshpass-1.05.tar.gz
sshpass-1.05/
sshpass-1.05/COPYING
sshpass-1.05/AUTHORS
sshpass-1.05/aclocal.m4
sshpass-1.05/INSTALL
sshpass-1.05/Makefile.am
sshpass-1.05/configure.ac
sshpass-1.05/install-sh
sshpass-1.05/Makefile.in
sshpass-1.05/sshpass.1
sshpass-1.05/configure
sshpass-1.05/depcomp
sshpass-1.05/README
sshpass-1.05/NEWS
sshpass-1.05/config.h.in
sshpass-1.05/missing
sshpass-1.05/main.c
sshpass-1.05/ChangeLog

Resources