LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-10-2018, 03:31 PM   #1
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Rep: Reputation: Disabled
Tar returns: Is a directory


Hi, I'm learning to use "tar" and when I run my script it sends me this error:

Code:
Fecha=`date +'%Y%m%d%H%M%S'`

`tar -cvPf /tmp/resp_${USER}_${Fecha}.tar /home/${USER}`
Code:
is a directory
I don't know what the cause is since I run it from the terminal and here it doesn't mark this message.
 
Old 08-10-2018, 04:15 PM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by m0rt View Post
Hi, I'm learning to use "tar" and when I run my script it sends me this error:

Code:
Fecha=`date +'%Y%m%d%H%M%S'`

`tar -cvPf /tmp/resp_${USER}_${Fecha}.tar /home/${USER}`
Code:
is a directory
I don't know what the cause is since I run it from the terminal and here it doesn't mark this message.
It's telling you what the "cause" is. /home/${USER} is the currently logged in user's "home" folder/directory. It's that simple.
 
Old 08-10-2018, 04:29 PM   #3
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jsbjsb001 View Post
It's telling you what the "cause" is. /home/${USER} is the currently logged in user's "home" folder/directory. It's that simple.
So for it to work I have to disconnect, but I ran it on another server and I didn't make a mistake.

How can I make it work for me?
 
Old 08-10-2018, 04:30 PM   #4
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Type this into a terminal and read it:

Code:
man tar
(you need to specify a file at the end of the path)
 
Old 08-10-2018, 04:40 PM   #5
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jsbjsb001 View Post
Type this into a terminal and read it:

Code:
man tar
(you need to specify a file at the end of the path)
What I'm trying to do is to back up the users' folders I have on my server, and when they run it to generate the backup in the /tmp path, I'm learning to make scripts.
 
Old 08-10-2018, 04:44 PM   #6
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
You probably don’t want -P. You also want to quote your variables. You probably want to use $( … ) instead of backticks.

Back to your problem, the issue is that you’ve surrounded tar execution in backticks. Get rid of them.
 
1 members found this post helpful.
Old 08-10-2018, 04:51 PM   #7
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
From tar's man page:

Code:
tar [OPTION...] [FILE]...
Once again, read it.
 
Old 08-10-2018, 04:54 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by m0rt View Post
I don't know what the cause is since I run it from the terminal and here it doesn't mark this message.
I'm unable to replicate the OPs problem. Their tar command creates a tar file of everything in the user's home directory with no "errors" or problems...

m0rt When you get the message, is the tar file not created?

Last edited by scasey; 08-10-2018 at 04:55 PM.
 
Old 08-10-2018, 05:05 PM   #9
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
I'm unable to replicate the OPs problem. Their tar command creates a tar file of everything in the user's home directory with no "errors" or problems...

m0rt When you get the message, is the tar file not created?
Yes, it does generate the file for me but my doubt is because it sends me the error, because I ran this script in SUSE and it doesn't send me errors, but in Ubuntu I get the message.
 
Old 08-10-2018, 05:10 PM   #10
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mina86 View Post
You probably don’t want -P. You also want to quote your variables. You probably want to use $( … ) instead of backticks.

Back to your problem, the issue is that you’ve surrounded tar execution in backticks. Get rid of them.
the -P is for me to respect the absolute paths otherwise it sends me another error message of the character "/"
 
Old 08-10-2018, 05:32 PM   #11
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by m0rt View Post
Yes, it does generate the file for me but my doubt is because it sends me the error, because I ran this script in SUSE and it doesn't send me errors, but in Ubuntu I get the message.
I can see that would cause a question.
Couple more suggestions:
  1. Compare the version and the man pages on the two machines. Look for a difference in what they say about the [FILE]...
    (Although my man page seemed to say the last option had to be a file or list of files, but worked with ${USER} just fine.)
  2. List the contents of the tar file where you get the "error" (I think it's only a warning if it's creating the file) to confirm that it contains all it should...maybe create a test user so it's not some huge collection of files to check.
 
Old 08-10-2018, 06:26 PM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by m0rt View Post
Code:
Fecha=`date +'%Y%m%d%H%M%S'`

`tar -cvPf /tmp/resp_${USER}_${Fecha}.tar /home/${USER}`
^                                                      ^
^                                                      ^
Code:
is a directory
What on Earth are those marked backtics supposed to be doing? What is happening is that the shell runs the tar command and then tries to interpret the verbose output as another command. The first line of that output will be the user's home directory, and the shell is complaining that a directory cannot be a command.

Last edited by rknichols; 08-10-2018 at 06:28 PM.
 
1 members found this post helpful.
Old 08-10-2018, 06:51 PM   #13
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by m0rt View Post
the -P is for me to respect the absolute paths otherwise it sends me another error message of the character "/"
Yes, that’s because typically having absolute path names in tar archives is a bad idea and may be dangerous. What you want is:
Code:
tar -C /home -cvf "/tmp/resp-$USER-$Fecha.tar" "$USER"
or slightly less magical:
Code:
cd /home; tar -cvf "/tmp/resp-$USER-$Fecha.tar" "$USER"
Unless you really want full path in the archive in which case:
Code:
tar -C / -cvf "/tmp/resp-$USER-$Fecha.tar" "/home/$USER"
Quote:
Originally Posted by scasey View Post
I can see that would cause a question.
Couple more suggestions:
  1. Compare the version and the man pages on the two machines.
No need for such tedious tasks. tar --version would very likely show that both systems use the same tar.

Quote:
Originally Posted by jsbjsb001 View Post
From tar's man page:

Code:
tar [OPTION...] [FILE]...
Once again, read it.
Perhaps OP has read it and noticed:
Code:
       For  example,  the c option requires creating the archive, the v option
       requests the verbose operation, and the f option takes an argument that
       sets  the  name of the archive to operate upon.  The following command,
       written in the traditional style, instructs tar to store all files from
       the  directory /etc into the archive file etc.tar verbosely listing the
       files being archived:

       tar cfv a.tar /etc
Emphasis mine. So yeah…

(But what confused me the most is why people continued discussing this after I’ve pointed out the problem).

Last edited by mina86; 08-10-2018 at 06:53 PM.
 
1 members found this post helpful.
Old 08-10-2018, 11:06 PM   #14
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by mina86 View Post
Yes, that’s because typically having absolute path names in tar archives is a bad idea and may be dangerous. What you want is:
Code:
tar -C /home -cvf "/tmp/resp-$USER-$Fecha.tar" "$USER"
or slightly less magical:
Code:
cd /home; tar -cvf "/tmp/resp-$USER-$Fecha.tar" "$USER"
Unless you really want full path in the archive in which case:
Code:
tar -C / -cvf "/tmp/resp-$USER-$Fecha.tar" "/home/$USER"

No need for such tedious tasks. tar --version would very likely show that both systems use the same tar.



Perhaps OP has read it and noticed:
Code:
       For  example,  the c option requires creating the archive, the v option
       requests the verbose operation, and the f option takes an argument that
       sets  the  name of the archive to operate upon.  The following command,
       written in the traditional style, instructs tar to store all files from
       the  directory /etc into the archive file etc.tar verbosely listing the
       files being archived:

       tar cfv a.tar /etc
Emphasis mine. So yeah…

(But what confused me the most is why people continued discussing this after I’ve pointed out the problem).
This happened to me to run my script. It came out as follows:
Code:
tar -C / -cvf "/tmp/resp-$USER-$Fecha.tar" "/home/$USER"
Output:
Quote:
tar: Removing leading `/' from member names
worked perfectly for me, thank you
 
Old 08-11-2018, 12:51 PM   #15
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by m0rt View Post
This happened to me to run my script. It came out as follows:
Code:
tar -C / -cvf "/tmp/resp-$USER-$Fecha.tar" "/home/$USER"
Output:


worked perfectly for me, thank you
Use home/$USER rather than /home/$USER (notice removal of leading slash) and the warning will go away.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script Issue with Tar Command: Either tar file created in wrong directory or not at all JockVSJock Linux - Newbie 4 06-09-2016 10:18 PM
Find returns : No such file or directory ? archuser Linux - General 5 05-23-2016 12:31 AM
I need to tar a directory and then copy it to another directory locally wdsmith45 Linux - Newbie 7 02-07-2012 11:49 AM
[SOLVED] Tar returns with error in Ubuntu 11.10 (tar version 1.22) call_krushna Linux - Server 3 01-06-2012 02:03 AM
Python script using tar from a list returns error: has no attribute 'startswith' linux1103 Linux - Newbie 3 04-05-2011 07:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration