LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices


Reply
  Search this Thread
Old 08-25-2010, 03:51 AM   #1
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Rep: Reputation: 15
Unhappy How to create batch file


Hello friends

i need to create a script called as batch file to copy library files every time with out calling every time to this location

/usr/local/lib

and replacing the old library files

i am doing all this to execute some c code on another machine using ssh

the the files i need to copy are in another location like

dvd/lib

can any one please guide me

thank you
 
Old 08-25-2010, 04:19 AM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Greetingz!

Let me make sure I understand your problem correctly;

Quote:
You need a script that will overwrite a set of known libraries in /usr/local/lib.
You need this done because you're going to call this new script from an existing script, or you're going to put the new script into cron.
Once you have this script, you will be able to SSH into another machine, so you can compile C code.
I *really* don't think you want to overwrite files in /usr/local/lib. That's just bad form, man.
Is SSH not working for you? Then you may have to define (or modify) your LD_LIBRARY_PATH environment variable before you start SSH.

However, if I'm completely off-base here, and you're trying to SSH into a system and THEN over-write the contents of /usr/local/lib, so you can compile something (that's looking for the libraries in dvd/lib), then I would still suggest you set LD_LIBRARY_PATH to /path/to/dvd/lib. Only you would do that *after* you logged in to the remote system via SSH.

However, if I'm really missing the point of your post, and assuming you have a known, always static (never changing) list of libraries to copy from dvd/lib to /usr/local/lib then you can do one of two things;

1) If you need to copy ALL libraries out of dvd/lib to /usr/local/lib
cp -Rvp /path/to/dvd/lib /usr/local/lib
(If you don't want to see all the output, read the man page for cp)

2) If you need to copy just a few files from dvd/lib to /usr/local/lib

a) create a text file somewhere (/tmp is a good place) and put the following in it;
/path/to/dvd/lib/libarary.1.so.0.1
/path/to/dvd/lib/libarary.2.so.0.1
/path/to/dvd/lib/libarary.3.so.0.1

(Note: make sure you change that to the paths and filenames you really needed)

Once you have this text file in /tmp (example: /tmp/libby.list), throw the following into a script and run it;

for fname in $(cat /tmp/libby.list)
do
cp -p $fname /usr/local/lib
done


I really hope that helps. For more tips, click the links in my signature for great justice! (lrn2post)

Last edited by xeleema; 08-25-2010 at 04:23 AM.
 
1 members found this post helpful.
Old 08-26-2010, 04:33 AM   #3
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
the thing is i installed some library files and there are some sample tests which are executed and got the outputs also and i need to open that output files on another machine using ssh

i copied the output files into that device and while i am running that output it saying some lib file is missing
which is older version(i had) and it is asking for another version, so i want to write a batch file which uses the required library files while executing every time

Last edited by badriinvenkat; 08-26-2010 at 04:37 AM.
 
Old 08-30-2010, 07:41 AM   #4
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
Please help me friends in solving my problem,

i need to use the library files(present in dvd/lib) for execution of my output file.

i need to do this execution using a batch file which uses the above mentioned library files.

i am doing all this in a web connected server using ssh
 
Old 08-30-2010, 01:33 PM   #5
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Lightbulb

Okay then, it sounds like this is what you're looking for;

Define LD_LIBRARY_PATH to /path/to/dvd/lib inside your batch file.

First check to see what it's already set to (if it exists at all) by running the following command;

echo $LD_LIBRARY_PATH

If it already exists, then you will put the following command inside your batch file (probably near the top, where you define other environment variables...if any);

export LD_LIBRARY_PATH=/path/to/dvd/libs:${LD_LIBRARY_PATH}
(this will put your needed library directory in the 'front' of the LD_LIBRARY_PATH)

If you don't already have LD_LIBRARY_PATH defined (e.g: the "echo" command from above does not show you anything), then you will have to put this command in your batch file, near the top;

export LD_LIBRARY_PATH=/path/to/dvd/libs

Hope this helps!
 
1 members found this post helpful.
Old 08-31-2010, 02:49 AM   #6
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
thanks every one, I created a batch file but how can i call it i mean how can i execute it???
 
Old 08-31-2010, 02:53 AM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Make the script executable
Code:
chmod +x scriptname
To run the script
Code:
path/to/script
 
1 members found this post helpful.
Old 08-31-2010, 03:06 AM   #8
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
thanks for u r valuable reply,

can you please explain in detail about 2nd command please
 
Old 08-31-2010, 03:07 AM   #9
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Please note that Linux's equivalent of DOS batch files is the shell script (.sh extension). If you try to run a .bat file on Linux you obviously will end up with plenty of syntax errors, as DOS/Windows commands are ***MUCH*** different from Linux/UNIX commands.
 
1 members found this post helpful.
Old 08-31-2010, 03:26 AM   #10
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
i had a file on sftp server in this location

[root@<DNS_Lookup_Failure> dvd]# ls
lib sergio setup.sh test

and i need to run the setup.sh

please tell me the exact commands to call it and execute it.
 
Old 08-31-2010, 03:57 AM   #11
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
Originally Posted by badriinvenkat View Post
i had a file on sftp server in this location

[root@<DNS_Lookup_Failure> dvd]# ls
lib sergio setup.sh test

and i need to run the setup.sh

please tell me the exact commands to call it and execute it.
Make the file executable,
To execute the script when you are in the directory containing the script
Code:
# ./scriptname
When you're not in the same directory give the whole path to the script
Code:
#/pathtoscript/scriptname
If you want to execute the script from every location, copy the script to a directory in your PATH, like
Code:
/usr/local/bin
then just type
Code:
# scriptname
Kind regards

Last edited by repo; 08-31-2010 at 03:59 AM.
 
1 members found this post helpful.
Old 08-31-2010, 03:58 AM   #12
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Okay, to simply run it:

Code:
chmod a+x setup.sh
./setup.sh
That's it. All you need chmod for is to edit the permissions on the script to make it executable. Then, the './' preceding 'setup.sh' indicates that the file is in the present working directory (PWD variable) and not in PATH (the system variable that tells the system where to look for executable files)
 
1 members found this post helpful.
Old 09-01-2010, 09:09 AM   #13
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
thanks for your valuable replies


i put this code in setup.sh file

cp -Rvp /path/to/dvd/lib /usr/local/lib

i tried to execute it

[root@<DNS_Lookup_Failure> dvd]# ./setup.sh
-bash: ./setup.sh: Permission denied
[root@<DNS_Lookup_Failure> dvd]# chmod a+x setup.sh
[root@<DNS_Lookup_Failure> dvd]# ./setup.sh
cp: cannot stat `/path/to/dvd/lib': No such file or directory
[root@<DNS_Lookup_Failure> dvd]#

i got this errors, can any one help me please,

thanks regards
 
Old 09-01-2010, 09:24 AM   #14
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Hi,

Could we see output from :

Code:
# cat ./setup.sh
 
Old 09-07-2010, 05:41 AM   #15
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
Hai every one....i just tried this to copy library files

cp -Rvp lib* /usr/local/lib

and i success fully copied the library files but it giving me result as

[root@<DNS_Lookup_Failure> dvd]# ./test1
Segmentation fault
 
  


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
How to create batch file? TigerLinux Linux - Newbie 16 09-26-2011 12:24 PM
how to create a batch file in linux sting1220 Linux - Newbie 7 12-23-2007 11:58 PM
Can someone help me to create a script that works like this batch file? Mysticle31 Programming 12 12-22-2007 06:10 PM
To create a batch file to use with a mem stick al bernier Programming 2 10-30-2006 10:33 AM
How to create a batch file? Franziss Programming 8 05-16-2005 12:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint

All times are GMT -5. The time now is 02:15 PM.

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