Linux Compatibility


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux Compatibility
# 1  
Old 08-04-2016
Hammer & Screwdriver Linux Compatibility

Hi all.

I'm in the process of migrating existing script on UNIX server to the LINUX platform.

One of the script that have issues is this one:
Code:
cd /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/

# GIANT #
rm -f INPUT_GIANT.csv
filename=INPUT_GIANT_*csv
GIANT_MONYYYY=$(echo $filename | awk '{print substr($0,length($0)-10,7)}')
# cp INPUT_GIANT_*.csv INPUT_GIANT.csv
tr '\r' '\n' < INPUT_GIANT_*.csv | grep -v '^$' > INPUT_GIANT.csv

After further investigation, this is due to the
Code:
filename=INPUT_GIANT_*csv

portion which mysteriously working when executed manually but not effective when run the whole script.

Error returned was:
Code:
debug_GST.sh: line 8: INPUT_GIANT_*csv: No such file or directory

So is there anyway to fix this since I need to put asterisk because I would not know what would be the actual file month.

Thank you.
# 2  
Old 08-05-2016
Change:
Code:
filename=INPUT_GIANT_*csv

to:
Code:
filename=$(printf '%s\n' INPUT_GIANT_*csv)

to fix your immediate problem. However, this will not work if the filename matching pattern INPUT_GIANT_*csv doesn't match any files in the current directory or if it matches more than one file.

Change:
Code:
GIANT_MONYYYY=$(echo $filename | awk '{print substr($0,length($0)-10,7)}')

to:
Code:
GIANT_MONYYYY=${filename%???}
GIANT_MONYYYY=${GIANT_MONYYYY#???????}

to make your script run faster. Of course since you haven't shown us an actual filename, this is just a guess; but it seems to be a reasonable guess based on the assumption that that line in your current script works on a UNIX system. (Or, if GIANT_MONYYYY isn't referenced later in your script, just get rid of that line.)
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-05-2016
Thanks Don.

Actually I've already fixed it by
Code:
for file in INPUT_GIANT_*csv; do filename=$file; done

Should be OK right? By right, there should be only one INPUT_GIANT_*csv at a time, it's just that the file month and year would be different.

By the way, does anyone knows why is that the
Code:
filename=INPUT_GIANT_*csv

works by manual typing in the terminal but failed with nohup sh?

Thank you.
# 4  
Old 08-05-2016
I would be very surprised if the command:
Code:
filename=INPUT_GIANT_*csv

ever did what you think it did. If you type in that command manually at a terminal while sitting in a directory where one file matching that pattern exists and immediately follow that command with the command:
Code:
printf 'filename: %s\n' "$filename"

I think you'll find that it prints:
Code:
filename: INPUT_GIANT_*csv

while the command:
Code:
printf 'filename: %s\n' $filename

(with the double quotes removed), prints:
Code:
filename: INPUT_GIANT_XXXcsv

where XXX is the string matched by the asterisk in your filename matching pattern.

You haven't shown us what your script does with the variables file, filename, and GIANT_MONYYYY other than the one place that $filename is expanded while setting the variable GIANT_MONYYYY. Without seeing how those variables are used in the rest of your script, it is hard to guess at what might be wrong.

With what you have shown us, it is hard to guess at why your script would work on a UNIX system (other than a Solaris/SunOS UNIX system) if you were using a Korn shell or a bash shell on both your UNIX system and on your Linux system.

What UNIX operating system were you using and what Linux system are you using now?

What shell were you using on the UNIX operating system and what shell are you using on your Linux system now?

Please show us your complete script as it was when it worked on the UNIX system you were using and please show us the complete script as it now appears on your Linux system.

Note that the error message you are getting is saying that when you run the command:
Code:
tr '\r' '\n' < INPUT_GIANT_*.csv | grep -v '^$' > INPUT_GIANT.csv

the pattern INPUT_GIANT_*.csv is not matching any existing file. Note also that the pattern used here is not the same pattern that was assigned to the variable filename. (One ends in .csv while the other one ends in csv (without the <period> character.) There is nothing in the command that is failing that refers to any variable. So, why do you think an expansion of the variable filename is your problem? (Or, did you not show us the first 8 lines of the script named debug_GST.sh?)

What output do you get from the command:
Code:
ls -l /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/INPUT_GIANT*

at a time when debug_GST.sh fails with the diagnostic you showed us in post #1 in this thread?
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 08-05-2016
Thanks again Don.

Code:
ls -l /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/INPUT_GIANT*

yields
Code:
-rw-r--r-- 1 edwh_test users 23082 Aug  5 16:05 /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/INPUT_GIANT_JUN2016.csv

So that's the file that expected to match.

UNIX:
Code:
HP-UX system1 B.11.31 U ia64 0189138652 unlimited-user license

LINUX:
Code:
Linux ex01db03.tm.com.my 2.6.39-400.264.1.el6uek.x86_64 #1 SMP Wed Aug 26 16:42:25 PDT 2015 x86_64 x86_64 x86_64 GNU/Linux

Manual typing to the terminal works as expected:
Image

So
Code:
filename=INPUT_GIANT_JUN2016.csv
GIANT_MONYYYY=JUN2016

I know it's a problem with that
Code:
filename=INPUT_GIANT_*csv

because it is inside the log temp.rst saying
Code:
debug_GST.sh: line 8: INPUT_GIANT_*csv: No such file or directory

.

After fixing the script, the log is empty
Code:
nohup sh debug_GST.sh > temp.rst &

Thanks a lot.
# 6  
Old 08-05-2016
Quote:
Originally Posted by aimy
Thanks again Don.

Code:
ls -l /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/INPUT_GIANT*

yields
Code:
-rw-r--r-- 1 edwh_test users 23082 Aug  5 16:05 /home/edwh_test/S13018/EDWH-DMT03/stgdata/RPT/INPUT_GIANT_JUN2016.csv

So that's the file that expected to match.

UNIX:
Code:
HP-UX system1 B.11.31 U ia64 0189138652 unlimited-user license

LINUX:
Code:
Linux ex01db03.tm.com.my 2.6.39-400.264.1.el6uek.x86_64 #1 SMP Wed Aug 26 16:42:25 PDT 2015 x86_64 x86_64 x86_64 GNU/Linux

Manual typing to the terminal works as expected:
Image

So
Code:
filename=INPUT_GIANT_JUN2016.csv
GIANT_MONYYYY=JUN2016

I know it's a problem with that
Code:
filename=INPUT_GIANT_*csv

because it is inside the log temp.rst saying
Code:
debug_GST.sh: line 8: INPUT_GIANT_*csv: No such file or directory

.

After fixing the script, the log is empty
Code:
nohup sh debug_GST.sh > temp.rst &

Thanks a lot.
Please copy and paste text rather than posting screenshots. (Especially screenshots with light purple text on a slightly darker purple background!)

You did not run the command:
Code:
printf 'filename: %s\n' "$filename"

(with the double quotes around $filename) as I requested. If you had run that command as I requested, you would have seen that the variable filename contains the filename matching pattern you assigned to that variable (i.e., INPUT_GIANT_*csv); not the filename matching that pattern INPUT_GIANT_JUN2016.csv.

You also did not show us your complete script. If you had shown us the original script that produced the diagnostic you showed us in post #1 in this thread:
Code:
debug_GST.sh: line 8: INPUT_GIANT_*csv: No such file or directory

and line 8 in that script did expand $filename, I would bet that it did so within double quotes like the printf command I asked you to run above using "$filename".

And, although I did have an off-by-one error since I didn't know what your filenames looked like. Your script will run faster if you change the lines:
Code:
GIANT_MONYYYY=$(echo $filename | awk '{print substr($0,length($0)-10,7)}')
# cp INPUT_GIANT_*.csv INPUT_GIANT.csv
tr '\r' '\n' < INPUT_GIANT_*.csv | grep -v '^$' > INPUT_GIANT.csv

in the script you showed us in post #1 to:
Code:
GIANT_MONYYYY=${filename%????}
GIANT_MONYYYY=${GIANT_MONYYYY#???????}
# cp INPUT_GIANT_*.csv INPUT_GIANT.csv
tr -d '\r' < $filename > INPUT_GIANT.csv

since it eliminates a subshell invocation and the invocation of two unneeded external utilities (awk and grep).
# 7  
Old 08-08-2016
What would happen if someone created a file called INPUT_GIANT_123 rm -rf * .csv?

I fear a simple use of filename=INPUT_GIANT_*.csv might evaluate this as:-
Set the variable filename to INPUT_GIANT_123 and then run rm -rf * .csv
which might not be what you actually want to do. This might not be malicious and could be an error typing on the command line.

You might well be safer to sanitise the input before using it openly.




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

OpenBSD fdisk - Linux fdisk compatibility ?

Hello, MBR partition table made by linux fdisk looks certainly not correct when printed by openbsd fdisk: Partition table created on linux (centos 6.3): # fdisk -l /dev/sdc Disk /dev/sdc: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 *... (2 Replies)
Discussion started by: vilius
2 Replies

2. Solaris

Solaris 10 - HW compatibility

Sorry, if this isn't the right forum for this question. I would like to compile an executable with gcc/g++ under Solaris 10 on the following OLDER SPARC-machine and then run this executable on the NEW SPARC-machine (see description down in this post). I'm wondering if it would be possible or if... (4 Replies)
Discussion started by: sunfire
4 Replies

3. SCO

Binary compatibility

Hi I'm going to buy C-ISAM 7.25 under sco unixware 7 to install in sco openserver 5.0.7. I'm wondering sco unixware 7 and sco openserver 5.0.6 are binary compatibles ? tnx (1 Reply)
Discussion started by: javad1_maroofi
1 Replies

4. Hardware

Linux Hardware Compatibility Guide (2007 HOWTO)

Before posting questions about Linux hardware, it is a good idea to check the Linux Hardware HOWTO guide (Last Update: 2007-05-22) However, this HOWTO has not been maintained since 2007 and it out-of-date. (0 Replies)
Discussion started by: Neo
0 Replies

5. Linux

Linux-laptop compatibility debate

Hey guys, i use my mac laptop and i love it, but i have decided its time to break the mold and use linux, and since linux on macs suck, i need to know what kind of pc to build... I want to know what kind of motherboard, wireless cards, hard drives, laptops, video cards, and etc. people have had... (3 Replies)
Discussion started by: mesaynaysayer
3 Replies

6. SCO

SCO 5.0.6 application compatibility w/ Linux?

Hello Valued Members, I was wondering if there are any Linux, BSD, versions that can run SCO 5.0.6 applications without much modification? I was looking into purchasing a copy of Caldera Openlinux, the last version, but wanted to ask if there are any other options of a newer variant. I am also... (8 Replies)
Discussion started by: stay0ut
8 Replies

7. Solaris

Disks compatibility

Hi all, I am trying to isntall veritas replicator on 2 DA 3000 storage , But with little luck . I am running a solaris 10 and vsf 4.1, Veritas Volume Replicator Option 4.1 My question is that : when i got the array i had 2 disks missing , So we had to replace them , but I found out that... (0 Replies)
Discussion started by: ppass
0 Replies

8. UNIX for Dummies Questions & Answers

Linux & Unix Compatibility

I am looking for a dual XEON or any dual CPU motherboard that can support Linux and Solaris at the same time. Does anyone have any idea? I am now looking at the TYAN S2507T / TYAN S2505T / TYAN S2720, you guys have any clue?:confused: (6 Replies)
Discussion started by: doyho
6 Replies

9. Shell Programming and Scripting

compatibility problem ??!!

hi! i have two problems with the following script who prepares a date (removes the heading zero from day if day<10) for arithmetical operations: <script> #!/usr/bin/sh DAY=`date +%d`; echo 1 - $DAY;#i.e. 06 DAY=${DAY#0}; echo 2 - $DAY;#i.e. 6 </script> 1. every time i run this... (3 Replies)
Discussion started by: oti
3 Replies

10. Filesystems, Disks and Memory

Motherboard Compatibility

Hi there,, I URGENTLY need to know if the Gigabyte GA 8IDML Motherboard is compatible with the Unix BSD. We need to know if we should buy new boards before we can use the product. Thanking you Hannelie Bosch:confused: :confused: (1 Reply)
Discussion started by: hbosch
1 Replies
Login or Register to Ask a Question