LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 04-14-2010, 03:00 AM   #16
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0

Thanks crts, grail and PMP for your replies.

grail, pls forgive me ignorance for not able to recognise the updated code from crts.
Thanks PMP for your code too.

It may make sense to reveal the actual concept of this script. The script is required as we have a bunch(nearly 100) of scripts written for HP-UX OS. And the person who wrote the scripts added the absolute path for each of the system commands (eg., for 'basename' he wrote as '/usr/bin/basename').

Now we are moving the server from HP-UX to Linux and because of these absolute paths attached to the commands, they might not work due to compatibility issues. So what i am trying to do is to insert a new line(PATH variable) into each of these scripts and strip off the absolute paths attached to each of the system commands in the script.

That is the reason for my request. I apologize for confusing you guys. But really appreciate your patience and time to respond to my queries.

Regards
 
Old 04-14-2010, 03:30 AM   #17
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Hello All

I slightly modified code from PMP and it worked.

the code i used is,

sed -i 's#/usr.[^ ]*/\|/sbin.[^ ]*/\|/bin.[^ ]*/##g' file

Thanks to everyone especially crts, PMP and grail.

Appreciate your help guys.

Regards
 
Old 04-14-2010, 03:41 AM   #18
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
As this is a migration, I personally would like to keep the absolute paths as there as chances that these scripts will be executed by user whose path variable is not set to read the commands.

What in-compatibility issues you discovered?
 
Old 04-14-2010, 04:50 AM   #19
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Hi PMP

I dont think that will be a problem because the user who will be executing the scripts will have the env set on login. And more over, as part of this script, we are inserting the line (export PATH=$PATH:..../.../...etc) at the top of each input script. So that shud solve the issue.

the compatibility issues are ... the commands actual location is different from HP-UX to Linux.

Regards
 
Old 04-14-2010, 04:54 AM   #20
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by PMP View Post
As this is a migration, I personally would like to keep the absolute paths as there as chances that these scripts will be executed by user whose path variable is not set to read the commands.
Until recently I used to fervently believe that; all my big scripts had an initialisation function, setting up a variable for each command (like ls=/bin/ls) and then testing them all to ensure they were set to an executable ordinary file.

Now I'm coming to think that the effort of doing that is not justified by the benefits and that a better solution is to explicitly set $PATH in the script, remove all aliases and then use command names without leading paths.

No answers -- only choices ...
 
Old 04-14-2010, 05:01 AM   #21
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by harsha1980 View Post
the compatibility issues are ... the commands actual location is different from HP-UX to Linux.
Which suggests solution by having a table of command fullpaths which differ and then replacing only those (with Linux fullpaths or with bare command names and then rely on $PATH; for consistency within the script the first has appeal).

A much harder issue to address is commands which take different options and harder than that are commands which produce differently formatted output (which is parsed by the scripts in a format-dependent way).

Are the special file paths/names identical?
 
Old 04-14-2010, 05:08 AM   #22
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Agree, for a fresh a script. But I personally will prefer to make a minimum change to the scripts written years ago!!
 
Old 04-14-2010, 06:24 AM   #23
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Yes. I agree with PMP. As the scripts are written a long time ago and we dont want to play with them.

As far as the "command paths that are changing" is concerned, they all are system commands and hence will be lying in standard paths like /bin, /usr/bin, /sbin etc. So we are including these in the PATH and inserting the same in each file.

Regards
 
Old 04-14-2010, 06:36 AM   #24
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by harsha1980 View Post
Yes. I agree with PMP. As the scripts are written a long time ago and we dont want to play with them.

As far as the "command paths that are changing" is concerned, they all are system commands and hence will be lying in standard paths like /bin, /usr/bin, /sbin etc. So we are including these in the PATH and inserting the same in each file.
Actually, in post #21, I was suggesting the least "playing with them". Rather than try and remove all paths with the possibility of collateral damage I was suggesting replacing only the specific paths that are different HP-UX/Linux.

If, for example, /usr/bin/ls on HP-UX was /bin/ls on Linux then you would change exactly that -- and so on for every other command identified as having a different path.
 
Old 04-14-2010, 06:45 AM   #25
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
I am not sure but a softlink can be an option as well, No change at all
 
Old 04-14-2010, 08:10 AM   #26
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Sorry catkin if i misinterpreted your comment in post #21.

The idea of creating a softlink was not permitted by the management during the initial discussions.

Regards
 
Old 04-15-2010, 05:04 AM   #27
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Hello Guys

The sed commands i used, which are working fine on Linux, aren't working on HP-UX.

1)
sed -e 's#/usr.[^ ]*/\|/sbin.[^ ]*/\|/bin.[^ ]*/##g' $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

2)
sed -e "1i'$top'" $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

3)
sed -e '2i\export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/' $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

when the script is run, 1) is not returning any error but simply not doing the job. but 2) and 3) are returning errors as below.

error for 2)
sed: Function 1i'#!/usr/bin/ksh' cannot be parsed.

error for 3)
sed: Function 2i\export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ cannot be parsed.


Any help is appreciated.

Regards
 
Old 04-15-2010, 05:23 AM   #28
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Check the sed version there, may be this is supported in Linux only.
Just a thought, why dont you copy the scripts on to linux and process them there
 
Old 04-15-2010, 05:57 AM   #29
harsha1980
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 0
The management want the scripts to work on both HP-UX and Linux.
 
Old 04-15-2010, 06:02 AM   #30
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
If I understand correctly, processing the file with sed is a onetime activity that you are doing, bring on the scripts to linux, make the modifications with the sed command that you are doing, copy the modified version back to HP-UX
 
  


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
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 04:58 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
delete a line containing a pattern and the next line of a text file powah Programming 3 01-31-2007 05:34 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM


All times are GMT -5. The time now is 04:28 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration