CAT EOF generated in a single line fail to run - unix

I have a yaml file where I want to write a XML:
script:
- >
cat > settings.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>$USERNAME</username>
<password>$PASSWORD</password>
<id>central</id>
</server>
</servers>
</settings>
EOF
If I run the cat command in my terminal, it works but when it's executed by my pipeline, this command become a single line failing:
cat > settings.xml << EOF <?xml version="1.0" encoding="UTF-8"?> <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <servers> <server> <username>$USER</username> <password>$PASSWORD</password> <id>central</id> </server> </servers> </settings> EOF
With the error:
parse error near `<'
Any idea how to fix this error or generate a well formated XML?

There are two problems:
Incorrect syntax (incorrect cat > settings.xml << EOF instead of correct cat << EOF > settings.xml)
The end-string EOF must be at the beginning of the line but it isn't.
To run this from the command line:
Type cat << EOF > settings.xml and press ENTER.
Paste (or type by hand) your XML document (without the end-string EOF) and press ENTER.
Type EOF (make sure it is at the beginning of the line!) and press ENTER.
You will be presented with the command prompt. Type ls -l settings.xml to see the newly created file.
To run this from a script:
Open your text editor and follow the steps 1, 2 and 3.
Save it under the name, lets say script.sh and make it executable:
chmod 755 script.sh
Run it:
./script.sh
When the command promt is back, type ls -l settings.xml, to see the newly created file.

Related

NOT getting output in test.out file using proenv, after executing .p file

i am a newbie on progress. i just followed the below kb article, but i am not getting the desired output.
https://knowledgebase.progress.com/articles/Knowledge/How-to-write-a-p-script-to-execute-via-proenv-to-produce-a-stderr-stdout-in-a-file
i have created a test.p file with below code:
MESSAGE ENTRY (1, "This is a test") VIEW-AS ALERT-BOX.
MESSAGE "Hello there" VIEW-AS ALERT-BOX.
DISPLAY "hello world".
chmod +x test.p
then in proenv i run below command
proenv>proenv -b -p test.p > test.out
i found only below output on test.out file
$ cat test.out
DLC: /opt/progress/117
WRKDIR: /opt/progress/wrk_117
OEM: /opt/progress/oemgmt_117
OEMWRKDIR: /opt/progress/wrk_oemgmt_117
Inserting /opt/progress/117/bin to beginning of path and
setting the current directory to /opt/progress/wrk_117.
OpenEdge Release 11.7.5 as of Fri Jun 7 08:29:03 EDT 2019
i am not finding, where i have done wrong. Appreciate help on this regards. Thanks.
Try
_progres -b -p test.p > test.out
or
bpro -p test.p > test.out
proenv launches a shell with DLC and other variables set. Proenv does not directly execute ABL code.

<< unmatched error from different user

I have a ksh function that runs good like this:
td_query () { bteq << EOF |grep '^>' |sed -e "s/^>//"
user/pass
DATABASE db;
$1
.LOGOFF;
.QUIT;
.EXIT
EOF
}
But when copy to another dir and run it under a different user, I get this error:
-ksh: .: syntax error: `<<' unmatched
why would it work under one user and not the other?
What else I can't figure out is if i login as the user it works under, then go to the other directory I just copied it too and try to run it from there, it doesn't work either...
you have a stray space in your heredoc redirection:
bteq << -EOF
^^
should be
bteq <<- EOF
^^
The hyphen belongs to the redirection operator. See the ksh93 man page (or ksh88)

zsh: reset stdout/stderr redirection

Something funky I gathered from the zsh man pages, is how you can redirect stdout and stderr to somewhere else, e.g. a file. It works like this:
logfile=/tmp/logfile
# Create a file descriptor and associate it with the logfile
integer logfd
exec {logfd} >> ${logfile}
echo "This goes to the console"
echo "This also goes to the console" >&2
echo "This goes to the logfile" >&{logfd}
# Now redirect everything to stdout and stderr to the logfile
# No output will be printed on the console
exec >&${logfd} 2>&1
print "This goes to the log file"
print "This also goes to the log file" >&2
For completeness' sake, a file descriptor can be closed by issuing exec {logfd}>&-.
I can just not figure out one thing. How do you reset zsh's redirections so that further output is again printed just to the console?
Found it after I issued ls -l /proc/self/fd/. Apparently there is a file descriptor 0 that can be used, it points to the console.
So, first we redirect back to that file descriptor:
exec >&0 2>&1
And now the log file can be safely closed:
exec {logfd}>&-
Ideal for scripts.

Is it possible to redirect stdout to a file location rather than a file descriptor?

My problem is that I am redirecting stdout/stderr to log files but logrotate comes and moves files around with output then going a file descriptor without a file.
Is there is any way in shell or at the system level to redirect the output to the new file at the same location?
If you don't mind re-opening the file for each line, instead of:
$ ... > logfile.txt 2>&1
do:
$ ... 2>&1 | while read line; do echo $line >> logfile.txt ; done

Installing Pear, what did I do by entering these commands on my terminal

I'm trying to figure out how to install Pear on my Mac (10.6.6).
Not understanding what they're telling me at pear.php.net, I got some code from http://clickontyler.com/blog/2008/01/how-to-install-pear-in-mac-os-x-leopard/
First, I entered curl http://pear.php.net/go-pear > go-pear.php in my terminal.
It resulted in this output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 88004 100 88004 0 0 47537 0 0:00:01 0:00:01 --:--:-- 59744
What does that all mean? Am I on the right track?
Next, I entered sudo php -q go-pear.php
and it gave me the long output below. In short I have no idea where I am in the installation process. However, I'm pretty sure that I'm not where I'm supposed to be at following the tutorial at http://clickontyler.com/blog/2008/01/how-to-install-pear-in-mac-os-x-leopard/
because the tutorial tells me to select all the default choices, and I don't see any options to select.
The next line of code is asking me to modify the php.ini files and it requires a password so I'm worried about doing it...Can anyone tell me if I'm on the right track?
sudo cp /etc/php.ini.default /etc/php.ini
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-s Output HTML syntax highlighted source.
-v Version number
-w Output source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--ini Show configuration file names
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--ri <name> Show configuration for extension <name>.
php does not have an argument -q. Its also mentioned in go-pear.php (http://pear.php.net/go-pear) itself, but I dont know, what it wants to tell me. However, try
sudo php go-pear.php
and then follow the instructions.
Update:
-q was used, to start the interpreter in "quiet" mode. It seems, that this option does not exists anymore, because php always starts "quiet", but it should not cause an error, anyway. Now make sure you are in the same directory as the file go-pear.php before you call php go-pear.php.
The first part shows that you successfully downloaded the file to go-pear.php.
The second part is showing that -q isn't a valid option. The third part is asking for the root password, since you're doing 'sudo'.
I used this, though I wasn't installing on Mac:
Getting and installing the PEAR package manager

Resources