This a really short question. But is there something syntatically wrong with placing a variable $example as an argument for tar in a bash file?
I have the file written as
//only portion that really matters
#!/bin/bash
...
tar -cvpzf $filename $backup_source
//here's the actual code
#!/bin/bash
backup_source="~/momobobo"
backup_dest="~/momobobo_backup/"
dater=`date '+%m-%d-%Y-%H-%M-%S'`
filename="$backup_dest$dater.tgz"
echo “Backing Up your Linux System”
tar -cvpzf $filename $backup_source
echo tar -cvpzf $filename $backup_source
echo “Backup finished”
//and heres the error
“Backing Up your Linux System”
tar: ~/momobobo: Cannot stat: No such file or directory
tar (child): ~/momobobo_backup/07-02-2013-18-34-12.tgz: 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
tar -cvpzf ~/momobobo_backup/07-02-2013-18-34-12.tgz ~/momobobo
Notice the "echo tar ...". When I copy and paste the output and run it in my terminal there is no problem taring the file. I'm currently running Xubuntu and I already did an update.
~ doesn't expand to your home directory in double quotes.
Just remove the double quotes:
backup_source=~/momobobo
backup_dest=~/momobobo_backup/
In cases where you have things you would want to quote, you can use ~/"momobobo"
Related
I am getting the following error when my bash script executes tar -xf
[21:02:51][Step 2/2] tar (child): lbzip2: Cannot exec: No such file or directory
[21:02:51][Step 2/2] tar (child): Error is not recoverable: exiting now
[21:02:51][Step 2/2] tar: Child returned status 2
[21:02:51][Step 2/2] tar: Error is not recoverable: exiting now
[21:02:51][Step 2/2] Process exited with code 2
I did check that I had bzip2 installed (as suggested in this answer):
Not quite sure if I need bzip2-libs:
The weird thing is, when I run the script manually from sh, it runs fine! But when I run it via TeamCity (which is running in Docker), it fails with the above error.
The script is literally the following (omitting some details):
#!/bin/bash
whoami
echo "$USER"
set -e
ScriptFilename=$0
ScriptPath=$(cd $(dirname $0) && pwd)
argn=$#
if [[ $argn != '1' ]]; then
echo "usage: ${ScriptFilename} phpArchivesDirTarFile"
exit
fi
phpArchivesDirTarFile=$1
function ExtractPhpArchives {
tar -C $ScriptPath -xf $phpArchivesDirTarFile
}
echo "ExtractPhpArchives"
ExtractPhpArchives
It results in the following TeamCity output:
Suspecting a permissions problem, I added "whoami" (which prints "root") and echo "$USER" which, a bit surprisingly, prints nothing.
What's more interesting, I have a backup copy or the tar file for which the script runs fine in TeamCity. But when I extracted the tarball contents and archived them again, I was back to the "Cannot exec" problem:
TeamCity settings:
Why am I getting this error and what else can I try to debug it?
have to use a .sh script to unpack and prep some databases. The code is the following:
#
# Downloads and unzips all required data for AlphaFold.
#
# Usage: bash download_all_data.sh /path/to/download/directory
set -e
DOWNLOAD_DIR="$1"
for f in $(ls ${DOWNLOAD_DIR}/*.tar.gz)
do
tar --extract --verbose --file="${DOWNLOAD_DIR}/${f}" /
--directory="${DOWNLOAD_DIR}/mmseqs_dbs"
rm "${f}"
BASENAME="$(basename {f%%.*})"
DB_NAME="${BASENAME}_db"
OLD_PWD=$(pwd)
cd "${DOWNLOAD_DIR}/mmseqs_dbs"
mmseqs tar2exprofiledb "${BASENAME}" "${DB_NAME}"
mmseqs createindex "${DB_NAME}" "${DOWNLOAD_DIR}/tmp/"
cd "${OLD_PWD}"
done
When I run the code, I got that error:
(openfold_venv) watson#watson:~/pedro/openfold$ sudo bash scripts/prep_mmseqs_dbs.sh data/
tar: data//data//colabfold_envdb_202108.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
I don`t understand why the code repeats my "DOWNLOAD_DIR", the correct should be :
data/colabfold_envdb_202108.tar.gz
and not
data//data//colabfold_envdb_202108.tar.gz
Could anyone help me?
New code:
set -e
DOWNLOAD_DIR="$1"
for f in ${DOWNLOAD_DIR}/*.tar.gz;
do
tar --extract --verbose --file="$f" /
--directory="${DOWNLOAD_DIR}/mmseqs_dbs"
rm "${f}"
BASENAME="$(basename {f%%.*})"
DB_NAME="${BASENAME}_db"
OLD_PWD=$(pwd)
cd "${DOWNLOAD_DIR}/mmseqs_dbs"
mmseqs tar2exprofiledb "${BASENAME}" "${DB_NAME}"
mmseqs createindex "${DB_NAME}" "${DOWNLOAD_DIR}/tmp/"
cd "${OLD_PWD}"
done
To answer your first question: why is it repeating? Because you are repeating it in your code:
for f in ${DOWNLOAD_DIR}/*.tar.gz;
do
tar --extract --verbose --file="${DOWNLOAD_DIR}/$f"
If f is downloads/file.tar.gz then ${DOWNLOAD_DIR}/${f} will resolve to downloads/downloads/file.tar.tgz.
As to your second question: the escape character is the backslash \, not the forward slash. Your multiline command should look like this:
tar --extract --verbose --file="${DOWNLOAD_DIR}/${f}" \
--directory="${DOWNLOAD_DIR}/mmseqs_dbs"
I'v 200.000 rows in file not_found_test1.txt
I'am running command as bellow, but getting error in first result
tar czvf /home/bukanadmin/test.tar.gz -T $(sed -n 1,10p /home/bukanadmin/not_found_test1.txt)
This is error what i got
tar: RT #StCecilias_PE\: Sara McBay y10 finished an impressive 4th in the JG 75m hurdles final. Sara only took up the hurdles a few months ago! #dedicated #workshard: Cannot stat: No such file or directory
tar: By stcecilias_re on 11-May-2018 17\:49: Cannot stat: No such file or directory
tar: at http\://twitter.com/stcecilias_re/statuses/994892363523874816: Cannot stat: No such file or directory
tar: : Cannot stat: No such file or directory
2018/05/2018-05-11/TWITTER.DATA_POST/abfeda55a6f5b9ad1622f5484c7452f1.txt
2018/05/2018-05-11/TWITTER.DATA_POST/73a38258c9e91110065c3973b90fc841.txt
2018/05/2018-05-11/TWITTER.DATA_POST/240ae384d7e1e1d2f5f4fa1f70e7f0e8.txt
2018/05/2018-05-11/TWITTER.DATA_POST/e5a6f6c8bccc3c1d0ed9f11eb543c0a2.txt
2018/05/2018-05-11/TWITTER.DATA_POST/23a051f72192affbe2e57e91df62e372.txt
2018/05/2018-05-11/TWITTER.DATA_POST/f629b60d212a04dc4d42695f348446f3.txt
2018/05/2018-05-11/TWITTER.DATA_POST/c7037ea6e3912496fc546b7135a763f3.txt
2018/05/2018-05-11/TWITTER.DATA_POST/93675eeb45dbd6385cbf37b0d9d39341.txt
2018/05/2018-05-11/TWITTER.DATA_POST/ded62f41db4a069bd4fd36e83661cdd2.txt
tar: Exiting with failure status due to previous errors
And when i remove Sed on command Tar, i got no issue
tar czvf /home/bukanadmin/test.tar.gz -T /home/bukanadmin/not_found_test1.txt
When i trying another command in Tar like command Head, i got same issue
Can someone help me and explain please
**NEW ISSUE :) **
Last issue is done
czvf /home/bukanadmin/test.tar.gz $(sed -n 1,10p /home/bukanadmin/not_found_test1.txt)
Now, i got error when i change my code to
czvf /home/bukanadmin/test.tar.gz $(sed -n 100000,200000p /home/bukanadmin/not_found_test1.txt)
This is error explain
-bash: /usr/bin/tar: Argument list too long
Using -T is meant to read the entire file, so trying to grab just the first ten lines won't work.
You can likely elimiate -T altogether and simply do:
tar czvf file.tar.gz $( sed -n 1,10p file )
...or using head...
tar czvf file.tar.gz $( head -10 file )
Instead of executing the following command:
tar -zcvf file.tgz fileX
I executed the following instead:
tar -zcvf fileX fileX
I encountered the following message on the screen:
tar: fileX: File shrank by 199917 bytes; padding with zeros
Now I see garbage data in fileX. Even when extracting the file fileX, I still see garbage.
i.e. tar -zxvf fileX
Is there any way to recover the data (using either linux commands or through hard-disk memory scans, etc)
I need to create a script which receives from the CLI the name of a file with the extension .tar.gz and a folder(e.g ./archivator.sh box.tar.gz MyFolder). This script will archive the files from the folder(only the files WITHIN the folder and without any compression) and they will be moved into the archive received as a parameter. The archive will be then encrypted(using the aescrypt) with the password 'apple'.
OS: Debian 6
Note: The final encrypted archive will have the same name as the first given parameter.
What i have tried so far is this:
tar -cvf $1 $2/* | aescrypt -e -p apple - > $1.aes | mv $1.aes $1
And this is what I receive when I am trying to check my script:
tar: This does not look like a tar archive
tar: Exiting with a failure status due to previous errors
Try doing this :
tar cf - $2/* | aescrypt -e -p apple - > $1
- here, means STDIN
Works well on Linux (archlinux) with GNU tar 1.26
If it doesn't work, run the script in debug mode:
bash -x script.sh
then come again to post the output.
After a little research, here is the solution:
pushd $2
tar cvf $1 .
openssl aes-256-cbc -in $1 -out $1.enc -pass pass:apple
mv $1.enc $1
popd
Your error seems to signal that the interpreter is receiving a file which is not a tar archive, yet it expects one. Have you checked to make sure the file your providing is a tar archive?