I'm having issues with double quotes and the eval command - linux

I am using a Linux command that shrinks a pdf using ghostscript from 100% zoom to 90% zoom. This command works properly from the Linux prompt:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=sam1.pdf -c "<< /BeginPage{0.9 0.9 scale 30.6 39.6 translate}>> setpagedevice" -sPAPERSIZE=letter -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" -dSubsetFonts=true -dEmbedAllFonts=true -f 2138WH.pdf
However, I'm trying to code this into a call from their ERP software (running on a SCO box) that needs to run the code on the Linux box. I'm struggling with the quotes, double quotes, etc. I've tried putting a \" in front of each quote with no luck. I think I need to use the eval command but I'm not sure. Any ideas on what needs to be done? Here is the latest change I've made:
eval ssh root#linux \""cd /submittals;gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=/submittals/012606-003e.pdf -c \""<</BeginPage{0.9 0.9 scale 30.6 39.6 translate}>> setpagedevice\"" -sPAPERSIZE=letter -dCompatibilityLevel=\""1.3\"" -dPDFSETTINGS=\""/printer\"" -dSubsetFonts=true -dEmbedAllFonts=true -f /submittals/012606-003b.pdf\""

eval is unnecessary and unhelpful (in this case), because it adds an extra layer of dequoting to your problem.
ssh root#linux "cd /submittals;gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=/submittals/012606-003e.pdf -c \"<</BeginPage{0.9 0.9 scale 30.6 39.6 translate}>> setpagedevice\" -sPAPERSIZE=letter -dCompatibilityLevel=\"1.3\" -dPDFSETTINGS=\"/printer\" -dSubsetFonts=true -dEmbedAllFonts=true -f /submittals/012606-003b.pdf"
I haven't tested this, but by eye it looks right.

Related

Rasa stack commands

I have got an error , error: unrecognized arguments: \ , while running below commands in Rasa stack bot bulding.
python -m rasa_core.run -d models/dialogue -u models/nlu/current \
--port 5002 --credentials credentials.yml
\ is used on Linux terminals to break up a command in multiple lines, e.g.:
copy file1.txt \
file2.txt
It seems that your terminal does not recognise \ properly. Are you using Windows as operating system?
On Windows you have to use ^ to break it in multiple lines, e.g copy file1.txt file2.txt becomes:
copy ^
file1.txt ^
file2.txt
If this also does not work you can also remove the \ and have the command in one line:
python -m rasa_core.run -d models/dialogue -u models/nlu/current --port 5002 --credentials credentials.yml
\ is used as notation for continuation of a command in Linux. Usually used when the command is very long, so that command is readable. In windows, you can execute without the \ character, it should work

Multiple commands in a pcmanfm-qt custom action?

SOLUTION AND THE COMPLETE EXEC LINE
Exec=sh -c 'sed -i "1s:.*:<body background=%f>:" /home/burak/Not/Shortcuts.mkd && pandoc -f markdown /home/burak/Not/Shortcuts.mkd --css /home/burak/Public/CSS/pandoc2.css -s -S -w html -o /home/burak/Not/Shortcuts.html && phantomjs /home/burak/bin/shortcuts.js file:///home/burak/Not/Shortcuts.html /home/burak/Not/shortcuts.jpg 1920px*1080px && feh --bg-fill /home/burak/Not/shortcuts.jpg'
This is likely relevant to other file managers using the same (DES-EMA) scheme.
I've got four commands all working individually, yet I stuck just at adding the second command to the Exec line of the custom action. If I overcome this, the other two remaining commands can be added accordingly (or by piping) I suppose.
Here are my commands and infos about what they're meant to do (the %f, obviously, to be expanded to the file clicked on in the file manager):
sed -i "1s:.*:<body background=%f>:" /home/burak/Not/Shortcuts.mkd
The above command replaces the first line of that markdown file which changes the background image of html file to be produced by pandoc with the following second command:
pandoc -f markdown /home/burak/Not/Shortcuts.mkd --css /home/burak/Public/CSS/pandoc2.css -s -S -w html -o /home/burak/Not/Shortcuts.html
The below third command converts that Shortcuts.html to shortcuts.jpg
phantomjs shortcuts.js file:///home/burak/Not/Shortcuts.html shortcuts.jpg 1920px*1080px
And finally the below fourth command sets the above shortcuts.jpg image as the desktop wallpaper (with all the shortcuts, bash aliases and some other commands embedded into the desktop).
feh --bg-fill %f
So at the end I would easly change wallpaper and embed my keyboard shortcuts and aliases etc. into every new wallpaper like so:
wallpaper with shortcuts embeded
Now, as said previously, I've stuck at the begining, that is, can't add the second command to the first. I've tried this without success:
Exec=sed -i "1s:.*:<body background=%f>:" /home/burak/Not/Shortcuts.mkd && pandoc -f markdown /home/burak/Not/Shortcuts.mkd --css /home/burak/Public/CSS/pandoc2.css -s -S -w html -o /home/burak/Not/Shortcuts.html
And neither this has worked:
Exec=sh -c "sed -i "1s:.*:<body background=%f>:" /home/burak/Not/Shortcuts.mkd && pandoc -f markdown /home/burak/Not/Shortcuts.mkd --css /home/burak/Public/CSS/pandoc2.css -s -S -w html -o /home/burak/Not/Shortcuts.html"
And piping (|) those two commands works in terminal, but not in custom action desktop file.
What should I do (on Arch Linux with Fluxbox if that matters)?
Damn!.. Thought I've tried this before, but seemingly not in this way. Well, piping in this manner works:
Exec:sh -c 'sed "1s:.*:<body background=%f>:" < /home/burak/Not/Shortcuts.mkd | pandoc --css /home/burak/Public/CSS/pandoc2.css -s -S -w html -o /home/burak/Not/Shortcuts.html'

Cropping a PDF with Ghostscript v7.07

I'm trying to crop a PDF that is purposely being output over sized since the program outputting it doesn't know the size of it's contents. On the FreeBSD system in question there is Ghostscript v7.07 installed. Based on the existing answer on another question (Cropping a PDF using Ghostscript 9.01) and adapting it to v7.07 documentation (http://ghostscript.com/doc/7.07/Readme.htm) I've tried the below replacing the -o with -sOutputFile= since it doens't recognize the -o.
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-c "[/CropBox [0 6785 433 7128]" \
-c " /PAGES pdfmark" \
-sOutputFile=testout.pdf \
testin.pdf \
and i've also tried
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-dDEVICEWIDTHPOINTS=433 \
-dDEVICEHEIGHTPOINTS=343 \
-dFIXEDMEDIA \
-c "0 6785 translate" \
-c "0 0 433 343 rectclip" \
-sOutputFile=testout.pdf \
testin.pdf \
My problem is that in both cases i just get the below message
**** Unable to open the initial device, quitting.
When searching for that error it mostly seemed to be due to the output file location not having write privileges or something similar to that, but that doesn't appear to be the case because I've chmod my folder to 777. The thing that drove me here is that if i remove the postscript command lines (-c) like below it outputs the testout.pdf file just fine (but obviously not cropped or translated to the correct position).
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-sOutputFile=testout.pdf \
testin.pdf \
and
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-dDEVICEWIDTHPOINTS=433 \
-dDEVICEHEIGHTPOINTS=343 \
-dFIXEDMEDIA \
-sOutputFile=testout.pdf \
testin.pdf \
I thought maybe 7.07 simply didn't support those commands since it doesn't seem to matter what i put within the -c it always ends up giving that error if the -c is there at all, but it is present in the 7.07 documentation (http://ghostscript.com/doc/7.07/Use.htm#General_switches) and it's not like it's giving me a -c is unknown error, so i'm at a loss. I figure I'm either doing something wrong, or there is something wrong with the ghostsciprt installation or it's dependencies. Any help anyone could give me would be greatly appreciated.
OK first off UPGRADE you are using a 13+ year old version of software.
Secondly, your command line is incorrect, you are using -c but you have not supplied the matching -f This means that everything after -c including the input and output filenames is being treated as PostScript.
Now a more recent version of Ghostscript would tell you that it needed an output filename, your incredibly ancient crufty version can only tell you that the device didn't open (because there was no output filename) which is why you get the misleading message.
Don't use -c twice, everything after -c (until -f) is treated as PostScript so you don't need to specify it twice.
I would expect this to work but since you are using so old a version I cannot be certain:
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-dDEVICEWIDTHPOINTS=433 \
-dDEVICEHEIGHTPOINTS=343 \
-dFIXEDMEDIA \
-c "0 6785 translate \
0 0 433 343 rectclip" -f \
-sOutputFile=testout.pdf \
testin.pdf

sed usage in x loader Makefile

What does this sed command do? when i run uname -m on my pc, it returns x86_64.
HOSTARCH := $(shell uname -m | \
sed -e s/i.86/i386/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/powerpc/ppc/ \
-e s/macppc/ppc/)
Note: code snippet from x loader Makefile.
The sed tries to show what system you run with a more readable name.
Eks if you have i.86 it shows i386
But the one who made the script did forget the intel 64 bits x86_64.

Opening terminal with multiple tabs using shell script

I am new to linux shell script. I want to write a shell script which will open terminal with multiple tabs. And in each tab it should run one rtsp client app.
i have written this code,
tab="--tab-with-profile=Default -e "
cmd="java RunRTSPClient"
for i in 1 2 3 4 5
do
#
foo="$foo $tab $cmd"
done
gnome-terminal $foo
exit 0
Its executing fine but it will open terminal and immediately it is closing.(I am not getting errors)
If I replaced the line foo=... with gnome-terminal --tab -e $cmd then its working fine but opens independent terminal.
suggest me how to fix this.
thank you
You should always (always!) use an array for building up argument lists in bash.
That is:
#!/bin/bash
# ^^ this has to be bash, not /bin/sh, for arrays to work
cmd=( gnome-terminal )
for ((i=0; i<5; i++)); do
cmd+=( --tab-with-profile=Default -e "java RunRTSPClient" )
done
"${cmd[#]}"
This will give you the exact equivalent of running:
gnome-terminal \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient"
...which is what I understand that you want.
Trying to build a complex command in a string causes Very Bad Things to happen; read http://mywiki.wooledge.org/BashFAQ/050 to understand why.

Resources