Create directories in stagging and informatica server

#!/bin/bash 
	echo " Script for creating new project in informatica"
	echo "  ***********************************************************"
	echo " First creating stagging area for new project"
	echo "  ************************************************************"
	echo "Enter the project name:"
	read proj_name
	export projectname=$proj_name
	echo "**************************************************************"
	echo " Select the Enviornment"
	echo "Choose Environment: (1-5)"
	echo "  1  -DEV/DEVL"
	echo "  2  -TEST/ALPHA"
	echo "  3  -PREPROD/BETA"
	echo "  4  -PT/SUPP"
	echo "  5  -PROD/VOL"
	echo "  *************************************************************"
	echo ""
	read Env
	export Env=$Env
	mkproj_dirs ( )
		{
			mkdir -p "$projectname"
			cd "$projectname"
			mkdir archivefiles dropbox logfiles lookupfiles maestro parameterfiles rejectfiles scriptfiles  sqlfiles stagefiles targetfiles
			chmod 775 .
			chmod 777 dropbox
		}		
		echo "***************************************************************"
	echo "Create directories in stagging and informatica server"
	echo "  *************************************************************"
	case $Env in
        1) 	export Env=devl
			export User=ecifetld
			mkproj_dirs "/webdata/ecif/etl/$Env/$projectname/"
			ssh $User@boom.nwie.net exec /bin/bash -s "$Env" "$projectname" < mkdir_infor.sh
			;;

Your script can't read from stdin. That's already being used to feed in the script, so your read commands eat part of the script.

Pass in variables into it like I showed you instead. They will be $1, $2, etc.

i tried this .. not sure if i followed u correctly.. or missing something.

case $Env in
        1)         export Env=devl
            export User=ecifetld
            # mkproj_dirs "/webdata/ecif/etl/$Env/$projectname/"
            export Env=$1
            export projectname=$2
            ssh $User@boom.nwie.net exec /bin/bash -s "'$1'" "'$2'" < mkdir_infor.sh

Got same error ... pls advice

Why do you have ssh inside the script when you're running this script on another server? I think you've gotten very confused along the way. Do all the ssh-es on the local side.

That's why I suggested doing what I did originally.

ssh username@host mkdir "'/path/to/whatever'" ';' tar -C "'/path/to/whatever'" -xf - < file.tar

Run that locally to create directories on the remote host. That should be all you need.

i am running script mkdir_infor.sh on remote server .Do you want me to copy this script on remote server to create the directories .. It would like copying script on env servers..
Any other suggestions..!
Thanks

Is it really your intent to ssh from server A into server B, so that server B can ssh into server C, to create directories on it? Why not just ssh into server C in the first place? :confused:

I think you've misunderstood the purpose of what I've suggested. You need to run these things on the local host. It makes no sense to run them anywhere but the local host. These commands log into the remote host and to the job you asked for -- creates directories on the remote host. By just dumping parts of what I've shown you in the middle of a script to be run on the remote host you're really changing the meaning of it.

I've shown you what you need to do. It's not an element of something you need to run anywhere else. It ought to work when run on the local host, allowing you to create directories on the remote host, as long as you've created a tar file like I illustrated earlier.

# Run this on the local host, to log into username@host and create directories in /remote/path/$ENV/whatever
ssh username@host mkdir "'/remote/path/$ENV/whatever'" ';' tar -C "'/remote/path/$ENV/whatever'" -xf - < ~/file.tar

Have you tried it yet? Not as part of a script, not sending it to the remote host, not anything but running this exact line on the local host with the paths you want on the remote host.

Does it work? Yes or no?

If not, in what way?

I intent to ssh server B from Server A and then create directories in server B.

---------- Post updated at 11:28 AM ---------- Previous update was at 10:15 AM ----------

Sorry, But i am not able to understand the code u suggested .
"# Run this on the local host, to log into username@host and create directories in /remote/path/$ENV/whatever
ssh username@host mkdir "'/remote/path/$ENV/whatever'" ';' tar -C "'/remote/path/$ENV/whatever'" -xf - < ~/file.tar"

It runs two commands on the remote server.

1) mkdir /remote/path/$ENV/whatever
2) tar -C /remote/path/$ENV/whatever -xf - < ~/file.tar

They are separated by ';', which will be fed into the other end as simply ; , as a separator between two shell statements. If you didn't put quotes around it, your shell would attempt to run tar on localhost instead of feeding the command into ssh...

The 1) command creates the base directory you want.

The 2) command extracts the tarball you made, of all the subdirectories with the permissions you wanted, inside /remote/path/$ENV/whatever. It reads from standard input.

~/file.tar, a file on the local host(not the remote host!), is the tarball I showed you how to create before. It is redirected into the standard input of ssh, so tar on the other end can read it from its own standard input without having to keep the file on the remote host.

All you have to do is substitute your own variables and filename into it, then run it locally.

1 Like

Got it.. i will try this and let u know...Thanks

---------- Post updated at 01:30 PM ---------- Previous update was at 12:13 PM ----------

for the this code :-

ssh $User@boom.nwie.net mkdir "'/$Env/ecif/etl/'" ';' tar -C "'/$Env/ecif/etl/'" -xf - < /webdata/ecif/etl/scripts/file.tar

getting this output:

ecifetld@ntac1rapvm0041> ./Create_proj_test.sh
 Script for creating new project in informatica
  ***********************************************************
 First creating stagging area for new project
  ************************************************************
Enter the project name:
TEST_ETL
**************************************************************
 Select the Enviornment
Choose Environment: (1-5)
  1  -DEV/DEVL
  2  -TEST/ALPHA
  3  -PREPROD/BETA
  4  -PT/SUPP
  5  -PROD/VOL
  *************************************************************

1
***************************************************************
Create directories in stagging and informatica server
  *************************************************************
Password:
mkdir: Failed to make directory "/devl/ecif/etl/"; File exists
tar: C: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile]  [exclude-file...] {file | -I include-file | -C directory file}...
 This complete creation of New Informatica directories kindy request permission change thru ITTL for Infromatica unix directories as below
 devl = eiccdevl:ecifetld
 alpha = eicctest:ecifetla
 beta   = eiccpprd:ecifetlb
 supp = eicctest:ecifetls
 vol = eiccpprd:ecifetlp
**************************************************************************************

In case you haven't noticed, code tags are not something that happens automatically. It's the moderation team following you around and cleaning up your mess. If you wish to participate here, please be a little more considerate and post in legible fasion using code tags where appropriate.

Anyway.

That output is impossible. You did not type in

ssh $User@boom.nwie.net mkdir "'/$Env/ecif/etl/'" ';' tar -C "'/$Env/ecif/etl/'" -xf - < /webdata/ecif/etl/scripts/file.tar

You typed in ./myscript or something like that, to run a ton of other things with it.

You also made one or more typoes in copy-pasting my code into your script. You left the dash off the -C, for instance, or added a space or something.

Please show what you actually did.

i dont understand what mess i created .. i m sorry but if my participation is not as per forums standard i will no more post .. Thanks for the assistance so far...

We're asking very little. Just [ code ] stuff [ /code ] without the extra spaces in tags, when posting code. Quote any of your own posts to see the changes I've edited into it, too.

We're still trying to help you. What exactly did you do to cause that output? What are the contents of the script you were running?

Script i ran:

read proj_name
export projectname=$proj_name
	read Env
	export Env=$Env
	mkproj_dirs ( )
{
	mkdir -p "$projectname"
	cd "$projectname"
	mkdir archivefiles dropbox logfiles lookupfiles maestro parameterfiles rejectfiles scriptfiles  sqlfiles stagefiles targetfiles
	chmod 775 .
	chmod 777 dropbox
}		
	case $Env in
    1) 	export Env=devl
		export User=ecifetld
		# mkproj_dirs "/webdata/ecif/etl/$Env/$projectname/"
		ssh $User@boom.nwie.net mkdir "'/$Env/ecif/etl/'" ';' tar -C "'/$Env/ecif/etl/'" -xf - < /webdata/ecif/etl/scripts/file.tar
		;;

Try reordering it into this

ssh $User@boom.nwie.net mkdir "'/$Env/ecif/etl/'" ';' tar  -xf - -C "'/$Env/ecif/etl/'" < /webdata/ecif/etl/scripts/file.tar

You did it again. You posted code outside of code tags.

We're asking very little. Just [ code ] stuff [ /code ] without the extra spaces in tags, when posting code. Quote any of the posts of yours I edited to see what I did. It's not hard at all.

Error for reordering:

mkdir: Failed to make directory "/devl/ecif/etl/"; File exists
tar: tape blocksize error

Progress, then. What is the system you're logging into? It seems to have a different version of tar than your local system.

You just posted code, outside of code tags. I had to edit your post to add code tags. If there was any indication you'd even tried to do as I and other moderators have asked, I wouldn't be bothering you. Please try adding code tags next time. Just [ code ] stuff [ /code ] without the extra spaces in tags, when posting code. Quote any of the posts of yours I edited to see what I did. It's not hard at all.

Sorry for not understanding ur direction seriously i am trying to do what u expect from me. The system in SunOS 5.10 .
This is my first ever posting in this forum ...Thanks for guiding me

That's what your remote system is; is your local system the same?

When you posted:

mkdir: Failed to make directory "/devl/ecif/etl/"; File exists
tar: tape blocksize error

you did so outside of code tags. We requested you do so inside code tags, like

[ code ] mkdir: Failed to make directory "/devl/ecif/etl/"; File exists
tar: tape blocksize error [ /code ]

...without the extra spaces inside the tags.

which would make it look like

mkdir: Failed to make directory "/devl/ecif/etl/"; File exists
tar: tape blocksize error

You could have quoted any of your posts to see what change I'd made in it.

Local :- Linux Remote : Sun Solaris...
Ok Now i understood what do u mean by code tags... i will follow this..Thanks

It's the tar file. I didn't expect a tarball made on linux to be fed to a solaris system. Here are modified instructions for creating a tarball in linux that ought to work on Solaris:

mkdir /tmp/skel
pushd /tmp/skel
mkdir -p archivefiles dropbox logfiles lookupfiles maestro parameterfiles rejectfiles scriptfiles sqlfiles stagefiles targetfiles
chmod -R 775 /tmp/skel
tar --format ustar -cf ~/skel-775.tar -C /tmp/skel .
chmod -R 777 /tmp/skel
tar --format ustar -cf ~/skel-777.tar -C /tmp/skel .
popd
rm -Rf /tmp/skel

If ustar doesn't work, try v7 or posix.

1 Like