LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-30-2009, 02:54 PM   #1
aamerjavaid
Member
 
Registered: Dec 2005
Posts: 53

Rep: Reputation: 15
problem after moving ksh script from windows to linux


Hi All,

I am facing a strange problem.

My simple problem is: i ftp my running ksh script from linux to windows and then to other linux box.

But my script is not working showing different errors.

Please let me know the solution and pls also how to coz i am have been just moved to this section.?

Thanks.

Aamer
 
Old 12-30-2009, 03:11 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Load the script in vim. If you see "^M" at the end of the lines, then run dos2unix to convert the script to use \n newlines instead of return&linefeed (\r\n).

You could use "head <filename> -n1 | od -c" to check the file manually. If you see "\r\n" at the end, you can use:
sed -i 's/\r//g' <filename>
to convert the script.

Also check the first line of the script. Does is start with "#!/usr/bin/ksh" or "#!/bin/env ksh". If not add this line. If your default shell is bash, you will see errors trying to run a ksh script.

Also make sure that the target system has ksh installed.

Last edited by jschiwal; 12-30-2009 at 03:22 PM.
 
Old 12-30-2009, 04:19 PM   #3
aamerjavaid
Member
 
Registered: Dec 2005
Posts: 53

Original Poster
Rep: Reputation: 15
Hi jschiwal,

Thanks for reply.

I loaded script in vim, didn't see any "^M" at the end of lines.

Then i run dos2unix to script. it converted successfully but when i tried running script, it abnormally exit my shell (no exit @ end of script).

then i tried option 2("head <filename> -n1 | od -c"). i saw "\r \n" at the end. i tried running sed -i 's/\r//g' <filename> to another copy of script and again my shell abnormally exited.

my script starts with "#!/usr/bin/ksh" but pls explain what is difference in these.

ksh is installed and my user's default shell is ksh.

Please help me out.

Thanks.

Aamer

Quote:
Originally Posted by jschiwal View Post
Load the script in vim. If you see "^M" at the end of the lines, then run dos2unix to convert the script to use \n newlines instead of return&linefeed (\r\n).

You could use "head <filename> -n1 | od -c" to check the file manually. If you see "\r\n" at the end, you can use:
sed -i 's/\r//g' <filename>
to convert the script.

Also check the first line of the script. Does is start with "#!/usr/bin/ksh" or "#!/bin/env ksh". If not add this line. If your default shell is bash, you will see errors trying to run a ksh script.

Also make sure that the target system has ksh installed.
 
Old 12-31-2009, 05:45 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Since you mentioned uploading the scripts to a windows computer, I considered the possibility that windows line endings were inserted. This can happen if you edit a script in windows, and sometimes by copying a file to a windows filesystem. Scripts and Makefiles will fail when this is the case.

The first line of a script tells the kernel which shell to use to run it.
#!/usr/bin/ksh indicates the full path to the shell. Because one installation might locate the k shell elsewhere, another way of doing the same thing is: "#!/bin/env ksh" which will launch the ksh if it is in your path. Portable Unix scripts tend to be written this way. The downside is that this practice is less secure if the environment variables can be manipulated. Especially for Unix and some BSDs where SUID scripts are allowed.

One thing I would recommend is using tar to archive your scripts into a tarball. Then FTPing them to windows won't change the line endings or the permissions or ownerships of the scripts. Since Linux/Unix use UID & GID numbers, you may need to use the "chown" program to make them runnable. Tar preserves the permissions so "chmod" probably won't be necessary.

Which two Linux distro's are you using. Does one of them use selinux or apparmor? If so, it's possible that security attributes or setting differences between the two distro's may be the problem. Files or directories these scripts try to read and write from could be protected by the SELinux or AppArmor.

Other things to consider is if there is a difference between the versions of ksh that your two distro's use. If the source distro uses a newer version of ksh and these scripts use new features, this might be the problem.

Also what do these scripts do? Are they distro specific and try to read or modify files that the other distro doesn't use? Some linux distros use System V style booting & process scripts and others use BSD style.

You may need to tackle one error at a time. At least post a couple as examples, and provide more details on what distro, distro version and architecture used.

Last edited by jschiwal; 12-31-2009 at 05:46 PM.
 
  


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
mv inside ksh script problem katkota Linux - Newbie 2 01-14-2009 09:01 AM
Porting ksh script from Solaris to Linux Gives unmatched if error markatharvestinfotec Programming 4 08-28-2008 02:51 PM
User input problem in a ksh script elmu Programming 1 11-20-2006 08:24 AM
ksh script problem pldobs Programming 2 12-25-2003 12:38 AM
Shell Script that misbehaves under Linux but works in HP UX well... ksh environ. sammathew Linux - Software 7 09-17-2003 09:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration