I have a series of perl scripts I am unsing since many years. Now I want to modify one of them and copy the code into a new file with another name (modified with _n) It is in the same location and with the same permissions. Running it I get
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
In the server log I read
End of script output before headers
I tried the same thing with other files that all work ok on my system, with the same result: Internal server error.
I also used a very simple script as
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use strict;
use warnings;
print "Hello, world!<br />\n";
with the same result.
What is the difference that leads to this error?
MacOS Big Sur 11.2.3
Perl 5.34, reinstalled
BBEdit 14.0.1
Fetch 6.8.2
adding -w to the shebang solved the problem. Silly...
Related
I'm creating a script that uses an external program that interacts with a server.
I want to test first that the program is installed before trying to use it.
I looked up the preferred way to tell if a program was installed and found this post:
How can I check if a program exists from a Bash script?
TLDR: It recommends "command -v <prog-name>" over "which <prog-name>" since it is POSIX compatible. The command should return 0 if the program was found, >0 otherwise.
So I used readProcessWithExitCode from System.Process as follows
readProcessWithExitCode "command" ["-v", "<some-program>"] ""
I get the following error when testing in GHCI
Exception: command: readCreateProcessWithExitCode: posix_spawnp: does not exist (No such file or directory)
I tried to use 'which' on 'command'. It tells me it does not exist although I can use it and it works as described in the man pages in my terminal.
What's going on here and how do I see if something is installed using Haskell?
Some system information:
GHC: 9.0.2
resolver: lts-19.11
"I use Arch btw"
I recommend that you simply run the program you want to run, and catch the exception you get if it isn't available. Like this:
catch
(callProcess "lol-this-does-not-exist" []) -- or whatever
(\e -> if isDoesNotExistError e then putStrLn "yikes" else throw e)
I am unable to install sdkman on my macos. I referred sdkman install and Can't install sdkman on Mac OS. Still, I am missing something. Can someone please help me ? I am new to MacOS and sdkman.
When I go to bash terminal and type curl -s "https://get.sdkman.io" | bash , it prints message failed to write body on terminal and opens my bash profile. What is that I am supposed to do next? I tried to follow steps mentioned at above urls, even used source as suggessted but I guess something is missing. I actually never write anything in bash profile, so source would not even do anything. I did multiple attempts using what I found online but sdk version never gives any output, it kept saying sdk command not found. I found online that I needed to upgrade curl, I even did that still no success. Can someone please write / explain steps for me that I am missing? I would appreciate it. I did search online, but either steps are not clear or I am not getting something right. Thanks.
It looks more likely that the piped bash closes the read pipe before the previous curl finishes writing the whole page. When you issue curl -s "https://get.sdkman.io" | bash, as soon as the piped bash has what it wants, it will right away close the input stream from the previous curl. But the cURL doesn’t really expect this and throws a “failed writing body” error. You might want to try piping the stream through an intermediary program that always reads the whole page before feeding to bash. For instance, you can try something like this (running tac twice before piping to bash):
curl -s "https://get.sdkman.io" | tac | tac | bash
tac is a Unix program that can concatenate and print files in reverse. In this case, it reads the entire input page and reverses the line order (hence we run it twice). Because it has to read the whole input to find the last line, it will not output anything to bash until cURL is finished. bash will still close the read stream when it gets what it needs, but it will only affect tac, which doesn't throw an error.
A formely working bash script no longer works after switching computers. I get the following error:
No such file or directory.
Before going on, please excuse any mistakes you may find since english is not my native language.
The script was used in cygwin under Windows XP. I now had to switch to cygwin64 under Windwos 7 (64bit).
The script is used as a checkhandler for the program SMSTools3 to split a file with a specific format into multiple smaller ones, which the program then uses to send SMS to multiple recipients. The script was copied directly from the page of SMSTools3 and uses the package formail.
After looking up the error the most likely problem was that the environmantle path was not set up to look in the right path (/usr/bin). I therefore added it to the path but to no avail.
I then deleted other entries in the enviromental path of windows which contained spaces because that could have been another explanation, but again to no avail.
Following is a minimal example of the code which produces the error.
#!/bin/bash
# Sample script to allow multiple recipients in one message file.
# Define this script as a checkhandler.
echo $PATH
which formail
outgoing="/var/spool/sms/outgoing"
recipients=`formail -zx "To:" < "$1"`
I added the lines the lines echo $Path and which formail to show if the script can find the correct file. Both results look fine, the second command gives me the right output '/usr/bin/formail'
But the line recipients=... throws me the error:
No such file or directory.
I do not have much experience with bash scripting, or cygwin in general. So if someone on this wonderful board could help me solve this problem, I would be really grateful. Thank you all for your help.
EDIT:
First of all thank you all for your comments.
Secondly, I would like to apologize for the late reply. The computer in question is also used for other purposes and my problem is part of a background routine, so I have to wait for "free time" on the pc to test things.
For the things #shellter pruposed: The ls command returned an error: '': No such file or directory.
The which -a formail as well as the echo $(which -a formail) commands that #DougHenderson pruposed returned the 'right' path of /usr/bin/formail. echo \$1 = $1 before the recipent line returned the path to the checkhandler file (/usr/local/bin/smsd_checkhandler.sh), the same command after the recipent line seems to show a empty string ($1 = ). Also, the pruposed change to the recipent line did not change the error.
For the dos2unix conversion that #DennisWilliamson pruposed, I opened the file in notepad++ to use their build in converion, but it showed me that the file is in unix format with Unix style line endings.
I am trying to run the below perl code from Windows batch file but getting error The file name, directory name, or volume label syntax is incorrect.
The script ran fine in eclipse.My ultimate goal is to run this perl script periodically using windows task scheduler, hence running it from a batch file.
Is there any other ways with which we can achieve my goal of running perl script on windows periodically?
I want my script to be functional across platforms, coz I have plans to run it from a mac as well.
use strict;
use warnings;
use Data::Dumper;
use File::Find::Rule;
my $basedir="G:\/My_Workspaces";
my #exclude_dirs= qw(.foo);
#Fetching all the workspaces under base dir excluding the ones in #exclude_dirs
my #subdirs =
File::Find::Rule
->mindepth(1)
->maxdepth(1)
->not_name(#exclude_dirs)
->directory
->in($basedir);
#Formating list of workspaces by removing the full path
s{^\Q$basedir\E/}{} for #subdirs;
If that is exactly the contents of your file, then you're asking Windows' command interpreter to process Perl source code, which it can't do
If you really need to create a batch file that has your Perl code embedded in it, then take a look at the pl2bat utility, which will do exactly that
A command like
pl2bat myperl.pl
will create a file myperl.bat that will run on the Windows command line and has your Perl source code embedded inside it. But that file is non-portable because it uses Windows commands that aren't recognised on a Mac or Linux platform
Either something doesn't know how to execute your Perl script, or your Perl script is being interpreted by something other than perl.
This could due to a problem with your file associations (or a lack thereof). Determining the exact cause would require more information.
In any case, executing perl with your script as a parameter rather than executing the script directly should solve the problem.
In other words, execute
perl script.pl
instead of
script.pl
Im new to to this Bash/Shell stuff and got to do some network analysis for a uni assignment.
Just trying to do a simple loop but getting a weird error that have been unable to fix despite a 2 hour google crawl:
#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done
I have tried using a for loop using the following syntax:
#!/bin/bash
for i in {1..5}
do
echo "Welcome $i times"
done
Whenever I place the first script on my server I get the following message:
./temp.sh: line 8: syntax error: unexpected end of file
Before running this file I have performed the following commands to add permissions and make the file executable:
ls -l temp.sh
chmod +x temp.sh
Just as a side note I found the following stackoverflow question about loops, copied the 'fixed code' and got the same error: Looping a Bash Shell Script
Im running version 4+ and using G-VIM as the text editor on Windows 7. Anyone got any ideas?
MANAGED TO SOLVE THIS MYSELF:
Seeing as my reputation is still too low I can't answer this myself at present so to stop people wasting there time here is how I fixed it:
Ok i've managed to fix this so will leave this up for anyone else who looks around.
My problem was that I was using FileZilla to connect to my server. It seems that even though I was using WinVi or G-Vim to create the files FileZilla was adding some form of extra characters to the end of my file when I transferred it to the server as im running Windows.
I switched to WinSCP as my connection agent and tried it and hey presto worked fine.
Thanks for the other answers.
Lewis
before running the bash script use the dos2unix command on it
dos2unix <bashScript>
./<bashScript>
Ok i've managed to fix this so will leave this up for anyone else who looks around.
My problem was that I was using FileZilla to connect to my server. It seems that even though I was using WinVi or G-Vim to create the files FileZilla was adding some form of extra characters to the end of my file when I transferred it to the server as im running Windows.
I switched to WinSCP as my connection agent and tried it and hey presto worked fine.
Do you have a newline after the done? That might account for the trouble.
Does it work with the bash in Cygwin on your machine? (It should; it works fine when copied to my Mac, for example, with any of sh, bash, or ksh running it.)
I also got this problem. Actually the solution for this problem is while writing script check in edit menu EOL Conversion is Unix format or not. It should be Unix format for shell script.