LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 04: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, 05:15 PM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: CentOS at the time of this writing, but some others over the years too...
Posts: 2,020

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
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, 05: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, 05:30 PM   #4
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: CentOS at the time of this writing, but some others over the years too...
Posts: 2,020

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
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, 05: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, 05:44 PM   #6
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 492

Rep: Reputation: 210Reputation: 210Reputation: 210
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, 05:51 PM   #7
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: CentOS at the time of this writing, but some others over the years too...
Posts: 2,020

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

Code:
tar [OPTION...] [FILE]...
Once again, read it.
 
Old 08-10-2018, 05:54 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,983

Rep: Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622
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 05:55 PM.
 
Old 08-10-2018, 06: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, 06: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, 06:32 PM   #11
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,983

Rep: Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622
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, 07:26 PM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,046

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
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 07:28 PM.
 
1 members found this post helpful.
Old 08-10-2018, 07:51 PM   #13
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 492

Rep: Reputation: 210Reputation: 210Reputation: 210
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 07:53 PM.
 
1 members found this post helpful.
Old 08-11-2018, 12:06 AM   #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, 01:51 PM   #15
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 492

Rep: Reputation: 210Reputation: 210Reputation: 210
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:18 PM
Find returns : No such file or directory ? archuser Linux - General 5 05-23-2016 01:31 AM
I need to tar a directory and then copy it to another directory locally wdsmith45 Linux - Newbie 7 02-07-2012 12:49 PM
[SOLVED] Tar returns with error in Ubuntu 11.10 (tar version 1.22) call_krushna Linux - Server 3 01-06-2012 03:03 AM
Python script using tar from a list returns error: has no attribute 'startswith' linux1103 Linux - Newbie 3 04-05-2011 08:17 PM

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

All times are GMT -5. The time now is 01:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration