unoconv return error when running as www-data - csv

When running this from command line as root it works
unoconv -f csv $file
But when running it as www-data this error is returned
Traceback (most recent call last):
File "/usr/bin/unoconv", line 1114, in <module>
office_environ(of)
File "/usr/bin/unoconv", line 203, in office_environ
os.environ['PATH'] = realpath(office.basepath, 'program') + os.pathsep + os.environ['PATH']
File "/usr/lib/python3.4/os.py", line 633, in __getitem__
raise KeyError(key) from None
KeyError: 'PATH'
update
echo shell_exec('echo $PATH');
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

centos 7.3 with php via php-fpm
the env in php is cleaned by php-fpm
u can use putenv to set evn["PATH"] in php code, examples
putenv("PATH=/sbin:/bin:/usr/sbin:/usr/bin");
var_dump(shell_exec('unoconv -vvvv -f pdf -o 123.pdf 123.doc));
or u can set env use one line shell cmd
var_dump(shell_exec('PATH=/sbin:/bin:/usr/sbin:/usr/bin'.' unoconv -vvvv -f pdf -o 123.pdf 123.doc));
or u can change /etc/php-fpm.d/www.conf to pass the env to php, add this line
clean_env = no
and the restart php-fpm
systemctl restart php-fpm.service

The PHP call you used (pasted from chat):
exec("unoconv -f csv $file")
My guess is that exec() is giving you an environment that is too limited. To work around this, you could set up a polled directory. The PHP script would copy files to be converted into the polled directory and wait for the files to be converted.
Then create a bash script (either running as root or a somewhat more secure user) to run in an infinite loop and check the polled directory for any incoming files. See How to keep polling file in a directory till it arrives in Unix for what the bash script might look like.
When the bash script sees incoming files, it runs unoconv.

Found a solution myself by running libreoffice directly
sudo libreoffice --headless --convert-to csv --outdir $tmp_path $file

Related

bash script continues to show "does not exist. file "

I'm running this bash scripts to read a CSV File which contains almost 10 lines with 05 columns:
Variables Global
DATE=$(date) #Set DATE equal to the output of running the shell command date
HOSTNAME=$(hostname) #Set HOSTNAME equal to the output of the hostname command
CSV_FILE='/scrpt/jobs_aix01.csv'
CSV_DELIMITADOR=','
#Variables
contador_sql=0
cadena_sql="error"
## Script
while IFS=\, read col_job_name col_os col_server col_user col_script
do
#echo "$col_job_name $col_os $col_server $col_user $col_script"
ls -l $col_script
done < "$CSV_FILE"
The script must read the CSV file and run the command ls -l but I get "does not exist. file "
Any ideas?
note: the files exist.
regards
unix jose

Unable to restore couchbase bucket using cbrestore

I am using Couchbase Server version 4.5.0 and trying to restore a saved backup version onto my local CB server. I am using macOS Sierra
Xcode Development tools are up to date
Python v2.7.10
I First created a backup by using this command
sudo ./cbbackup HOST:PORT ~/Documents/ -u ‘username’ -p ‘password‘ -b BUCKET_NAME
After this I tried restoring this backup onto local Couchbase server using this command
sudo ./cbrestore /path/to/backup/2017-01-24T121528Z/2017-01-24T121528Z-full/ http://localhost:8091 -u ‘USERNAME’ -p ‘PASSWORD’ --bucket-source=SOURCE_BUCKET_NAME --bucket-destination=DESTINATION_BUCKET_NAME
but I am getting following error.
Exception in thread s0:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_mc.py", line 91, in run
rv, batch, need_backoff = self.scatter_gather(mconns, batch)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_cb.py", line 72, in scatter_gather
rv, conn = self.find_conn(mconns, vbucket_id, msgs)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_cb.py", line 316, in find_conn
host_port = serverList[vBucketMap[vbucket_id][0]]
IndexError: list index out of range
If you took you're backup on a non-osx version of Couchbase and are restoring to an osx version then you need to use "-x rehash=1" with cbrestore. The reason is that the osx version of Couchbase is for development only and has less vbuckets then the standard (non-osx) Couchbase versions. The rehash flag tells cbrestore to deal with the different number of vbuckets.

Execute Multiple Command Using Batch File and install MySQL using batch file

I'm trying it write a window batch file to perform several tasks in series, However, it always stops after tie first command in the script.
I am use this this batch file code:
start cmd /k cd %CD%mysql\bin && mysqld --install
I want to use this batch file command and install the MySQL but it run only only one command
You have the following command in your batch file:
start cmd /k cd %CD%mysql\bin && mysqld --install
Lets break it down into smaller pieces.
start start a program, command or batch script (opens in a new window.)
cmd /k cd %CD%mysql\bin run `cd %CD%mysql\bin and then return to the cmd prompt.
&& if the above succeeds then run the next command
mysqld --install run mysqld --install if start cmd /k cd %CD%mysql\bin succeeded
The second part will never run as the first part returned to the command prompt.
Try the following batch file instead:
cd %CD%mysql\bin
mysqld --install
Note the variable CD must be assigned a sensible value, otherwise cd %CD%mysql\bin will fail.
Seems you have a lot of layers here: both start and cmd /c (which I think you'd prefer over cmd /k for use in a batch file).
What's wrong with just cd %CD%\mysql\bin && mysqld --install? This worked fine for me when I attempted to run notepad.exe thus: cd /d %WINDIR%\System32 && notepad (note the additional '\' character here, just in case ... an extra backslash won't hurt if env var CD already has one). For that matter, I'll bet %CD%\mysql\bin\mysqld --install would work just fine.
However, just in case you want the extra cruft – or, more likely, need it for some other functionality you're not showing. Using just cmd:
cmd /c "cd %CD%\mysql\bin && mysqld --install"
using just start:
start "" "cd %CD%\mysql\bin && mysqld --install"
I'd put a solution using both start and cmd, but you just don't need it.
BTW, if you can't just call %CD%\mysql\bin\mysqld --install directly, I'd look into using pushd instead of cd, so that you can call popd at the end of your overall script ... it's just good form to put your script user back in the directory in which they started.

How to make automatic backups of mysql db´s on Goddady with Apache servers

Im trying to automate a daily backup of mysql database on a shared hosting with Godaddy.com using Apache servers.
For this I researched and found out about bash scripts.
Goddady hosting lets me do cron jobs also so I did the following:
My bash script looks something like this (I masked the sensible data only):
<br>
#/bin/sh<p></p>
<p>mysqldump -h myhost-u myuser -pMypassword databasename > dbbackup.sql<br>
gzip dbbackup.sql<br>
mv dbbackup.sql.gz _db_backups/`date +mysql-BACKUP.sql-%y-%m-%d.gz`<br>
</p>
I configured the cron job which points to this file and executes it every 24 hours.
I have the cron job utility configured to send me a log message to my email every time it runs.
And this is the log message:
/var/chroot/home/content/01/3196601/html/_db_backups/backup.sh: line
1: br: No such file or directory
/var/chroot/home/content/01/3196601/html/_db_backups/backup.sh: line
3: p: No such file or directory
/var/chroot/home/content/01/3196601/html/_db_backups/backup.sh: line
4: br: No such file or directory
/var/chroot/home/content/01/3196601/html/_db_backups/backup.sh: line
5: br: No such file or directory
/var/chroot/home/content/01/3196601/html/_db_backups/backup.sh: line
6: /p: No such file or directory
Its like it doesn't understand the language. Should I edit my .htaccess file for this?
Any ideas?
Remove those html tags from the bash script, error messages are all related to them . Your script should be as the following.
#!/bin/sh
mysqldump -h myhost-u myuser -pMypassword databasename > dbbackup.sql
rm -rf dbbackup.sql.gz
gzip dbbackup.sql
mv dbbackup.sql.gz _db_backups/`date +mysql-BACKUP.sql-%y-%m-%d.gz`

Dump MysqlDB and transfer it to FTP

I had created a batch file
#echo off
echo Running dump...
CD c:\Program Files\MySQL\MySQL Server 5.5\bin
CALL mysqldump --user=1234 --password=aaaa dba1 --result-file="c:\Users_%DATE%.sql"
echo Done!
and I dont know, how to transfer it to ftp;
How about using ftp command line utility?
It is capable of using scripts (lists of commands from external files)
ftp -s:ftpcmd.dat your.ftp.server.com
Now you can either create this script file beforehand or make it on the fly from your batch file using echo.