I am trying to run a shell script that tests the connectivity to all the sftp servers and email if any one of them is down. There are aliases for all the servers with sftp command prefix in a '.alias' file. But when I use the alias name to run it as a command in my shell script to test the connectivity, I get an error saying "not found [No such file or directory]", though I initialize the .alias file at the beginning of my script.
Below is what I m doing. Please help me to resolve this.
.alias file have entries like:
In the script I am doing the below:
#Where Alias_List.txt has the list of all sftp server alias names, i.e abc, xyz
My question is: why is it "source .alias" NOT setting/initializing the alias names in the session? is adding these alias names to /etc/bashrc file the only solution? Can't I handle it within the script?
Any help is much appreciated. Thanks in advance
Regards,
Dippu
Moderator's Comments:
Please use code tags next time for your code and data, thanks
If your alias-file holds this content as stated, then it won't work because the alias-definition doesn't work. Remove the the superfluous blanks and - maybe not necessary, but i like to play it safer than necessary - quote in the strictest form.
Furthermore I'd include the path to the sftp-executable into the alias:
Thanks for your quick response Bakunin.
Sorry the alias command I gave have extra spaces but in original file, they aren't there. So yes the alias itself works fine, as I sourced it in my local session and ran the alias as a command and it works fine as it logs on to the sftp server.
But the problem is only when I run it in a script.
Also I just tried with absolute path of the sftp executable in the alias definition and even that doesn't work.
I wonder how can I make aliases visible in my shell script! OR the way I am executing the alias command, by just calling the alias: abc in my script not the correct way?
There seems to be a lot of disagreement on this, but as I understand it, aliases are for interactive use -- not generally for scripted use. For scripts, you'd use functions. It's possible to enable aliases in noninteractive scripts in some shells, but if you feel the need to do so, there may be design problems underlying your work.
Your "here document" in particular has me worried that you are expecting alias substitutions to happen in a place they never will, however -- inside things like here-documents, dynamically generated code, etc. It'd take an eval to shoehorn them in there, which is a class-9 bad idea for a variety of reasons. Could you tell me exactly how you are trying to use these aliases?
I am trying to initialize a file name in bash but not having much luck. For example, one of my bash scripts outputs a file named "FILE_1000G.vcf". I would like to rename FILE to match with the user's name. This is my code:
set -e
echo "Please enter your filename:"
read filename
rename... (6 Replies)
i have defined a function ln_s() for customizing the ln command in script1.sh.
more script1.sh
echo "Starting Execution"
./script2.sh
echo "End of Execution"
ln_s(){
] && return
ln -s "$1" "$2"
}
My script1.sh executes another script2.sh which has the following entry
more script2.sh... (12 Replies)
Hi,
I am having a shell script on Solaris 10 which has a while loop as shown below.
#!/usr/bin/ksh
#
while
do
sleep 60
done
Name of the shell script is coldcentric.sh. I executed script /DATAWAREHOUSE/LOAD/Scripts/coldcentric.sh from a command task in Informatica worklow as... (3 Replies)
Hello,
I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes.
... (2 Replies)
Hi all,
I want to use perl string manipulation commands in my shell script.
I have written following script.
echo "enter name"
read name
perl -e '$m=length($name);
echo $m
it gives an error: unrecognized token in perl command line.
do not suggest me an equivalent command of shell... (3 Replies)
Hi
I have to execute the commands in .aliases file from a shell script
I tried
1.giving the alias directly in shell script
2.Giving the actually "value of alias" in the shell script
3. I tried giving both steps 1 and 2 inside ` quotes
Still nothing is working . It says command... (3 Replies)
I am not able to access the aliases in my environment within a Python script. If I pass the alias to os.system(), I get a message saying "sh: x: not found". I've tried sourcing my .bashrc file in the script, but this does not work. I would perfer not to source my or any rc file because this... (9 Replies)
Hi All,
i am running a shell script in which there is a command
`ps -ef | grep smon > db`
When i execute this command in the command prompt i am getting the desired output..but when the script is executed..the db file is getting created but with no values...I could not find the reason for... (2 Replies)
I've a shell script that invokes a URL of an application to do some work, e.g., http://www.abc.com/myservlet?action=helloworld.Does the shell wait for a return value from the URL call before proceeding to the next line of command? (6 Replies)