Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients).
I have a (working) Perl script that I want to call. This Perl script takes an RSpec and finds the machine names and/or IP addresses, and prints them to the STDOUT.
What I want to happen is for the bash script to call the perl script (which is in a subdirectory), and pipe the output to a .txt file. Right now, I keep getting an error saying the perl script doesn't exist, though I am giving it the full pathname.
This is the bash script:

#!/bin/bash
case $# in
3) ;;
*) printf "Need three arguments!\n"
   exit 1 ;;
esac

perl "$HOME/Documents/begPerl/etIDs.plx" "$1" > "$HOME/Documents/ AllMachines.txt" || exit 1

The error I'm getting is:

Can't open perl script "/home/*****/Documents/begPerl/getIDs.plx": No such file or directory

If it helps any, I'm using ubuntu on a VirtualBox VM (physical machine is a MacBook Pro). (The starred out text was a folder containing my name...)
Any and all help (and explanations, too) would be greatly appreciated. I'm relatively new to both perl and bash (only been using these languages for a few months).
I am aware that there are other threads dealing with similar topics, but I could not find one that suited this problem specifically.

I see no / in front of home there, which means it starts looking for 'home' in the current directory, not in the root folder.

Try ~/"rest of path" instead of $HOME

Thank you, but this did not work. The error is exactly the same as before.

Yeah. On many shells, cd ~ is treated as a synonym for cd $HOME , however cd ~logname (where logname is your login name) should work.
But the real issue is that $HOME has been set incorrectly; it should ALWAYS be an absolute pathname.

It looks like you may have accidentally removed the leading "/" from $HOME. If you log out and log back in and $HOME still does not start with a "/", you'll need to dig through your shell's initialization files and correct the line that sets HOME.

Until you find the problem, assuming your login name is mecaka, the following should get your current shell execution environment back to a reasonable state:

cd ~mecaka
HOME=$PWD
export HOME

I just went back and read my original post. I am not posting this from the browser on my VM, so I could not copy and paste... There is a backslash before home, and there has been the whole time. I apologize for this confusion. I will correct this in the original.

However, if this was not the issue, what is? The PWD is "/home/*****/Documents" (assuming this helps any...)
I must add, I don't know much about the behind-the-scenes workings of programming. There might be something quote-en-qoute "obvious" that I wouldn't have caught.

Sometimes, 'file not found' can mean it can't find a library. Check that perl runs properly when you run it by hand.

But I suspect it really means what it says -- the file really, genuinely isn't there. Look very closely for typos.

1 Like

Wow... Yeah, the actual filename was "getIDs.plx", my code said "getIds.plx", and the code I posted didn't have the 'g'... Thanks for pointing that out! :slight_smile:

1 Like