AIX Version 6.1 tar script

83 Views Asked by At

I need to create a script in AIX Version 6.1 that create a zip file containing a txt and several pdf. I am not used to scripting in this environment except for some basic so I am sure I am missing something obvious and I try to provide as much info as I can about what I am doing. Here the script I set (createzip.sh):

tar -cv myArchiveName.zip 
tar -rvf myArchiveName.zip *.txt 
tar -rvf myArchiveName.zip *.pdf 
rm *.txt 
rm *.pdf

Executing each one via command line that results as I expect without errors, but using createzip.sh this error is raised:

tar: /dev/rmt0: The file access permissions do not allow the specified action.

Here the permissions

-rwxr-xr-x    1 oracle   dba             234 Aug 31 09:31 createzip.sh

I split the tar command in multiple calls because the final script would be like :

tar -cv myArchiveName.zip && tar -rvf myArchiveName.zip *.txt && tar -rvf myArchiveName.zip *.pdf && rm *.txt && rm *.pdf

*** EDIT AFTER ANSWER ***

I was creating the archive on Unix system and "reading" on in Windows system so I don't notice any error in files due to naming the archive with extension zip. No specific request about the archive extension so I can use tar without focusing on this matter. I use multiple instrucions in order to trace/log steps and concatenate them.

I modify the script like this:

tar -cvf myArchiveName.tar *.txt && tar -rvf myArchiveName.tar *.pdf && rm *.txt && rm *.pdf

Trying to execute createtar.sh raise this error:

createtar.sh: not found.

The script execute correctly only with dot command (full stop)

. createtar.sh

but is not clear to me which is the meaning/function of it.

1

There are 1 best solutions below

6
Romeo Ninov On BEST ANSWER
  1. tar do not create zip file, it create tar file
  2. in UNIX you need to specify the filename otherwise tar use first tape device:
    tar -cvf myArchiveName.tar *.txt *.pdf
  3. You do not need to explicitly add files (-r), combine them as show above
  4. The same is true about rm command:
    rm *.txt *.pdf

You can create it on line like this:

tar -cvf myArchiveName.tar *.txt *.pdf && rm *.txt *.pdf