I use mysql with zend.
I'd like to do an apple script to backup one database on a specific folder.
I know how to do in php but not with applescript.
See below my script in PHP.
<?php
require_once ('../MySQL.php');
require_once ('../conf.php');
include('../functions.php');
echo '----------------- Dump mySQL-----------------<br>';
$NameFile=DB_DATABASE . date("Y-m-d-H-i-s") . '.sql';
$backupFile =$_SERVER['DOCUMENT_ROOT'].'/MySoft/backup/'.$NameFile;
$commandMac = '/usr/local/zend/mysql/bin/mysqldump -h '.DB_HOST.' -u '.DB_USER.' -p'.DB_PWD.' -B '.DB_DATABASE.'>'. $backupFile;
system($commandMac);
?>
So could you help me to do the same with applescript.
Thanks
The simple method would be to run the php script from applescript. Something like this would work...
set phpScriptPath to "/path/to/phpscript"
do shell script "php -q " & quoted form of POSIX path of phpScriptPath
I think that's the easiest way
set shellScript to "/usr/local/mysql/bin/mysqldump DatabaseToDump > FileWhereToDump.sql"
do shell script shellScript
This approach, which uses shell scripting only and should work with a local MySQL.
DatabaseToDump being the database you wish to dump and FileWhereToDump.sql the target.
Related
I have a shell file and in that I need to create and write a content as below into my abc.properties file.
version=123456-> This is the one thing which is required in my properties file.
I tried with the below commands and its not writing the contents into the file.
sh "touch abc.properties"
sh "lscm show lastmod . -f yyyyMMddHHmmssSSS >> ${lscm_home}/abc.properties"
Can someone provide some inputs on how can i make the second command to write into the required file ? Thanks
You can try like below
echo "Version=`lscm show lastmod . -f yyyyMMddHHmmssSSS`" >> FILE_NAME
I have a shell script like getlist.sh it has a below hive command inside it.
`hive -e "select * from databasename.tablename where name = 'myname';" > /home/testuser/list.tsv`
when run the getlist.sh manually it works fine, when I schedule it using cron it creates the file but with no record in it.
Can someone correct me, couldn't figure out where I'm going wrong.
I fixed it by adding #!/bin/bash instead of #!/bin/sh in getlist.sh script. it did the trick.
I'm writing a shell script. what it does is it will create a file by the input that is received from the user. Now, i want to add the feature called "view a file" for my current script. Now, it's unreasonal to retype it again since i've already had a script that helps
I know it's crazy when it is possible to it with normal shell command. I'm actually writing a script that help me to create pages that are generated from the touch command. (this pages had attached date, author name, subjects, and title).
The question is how to call a another script or inhere another script?
Couple of ways to do this. My prefered way is by using source
You can -
Call your other script with the source command (alias is .) like this: source /path/to/script.
Make the other script executable, add the #!/bin/bash line at the top, and the path where the file is to the $PATH environment variable. Then you can call it as a normal command.
Use the bash command to execute it: /bin/bash /path/to/script
I wrote an applescript that makes use of an external command line script that helps to perform clicks.
Now, if I want to publish my script, what should be my approach to the end users? I mean, should I say to them: "first of all you have to download this CLI utiltity, and put in this folder... then download and run my script!"
This is a newbie question but: is this the only way to do this? or can I include in some way the CLI code in my script/package? If yes how?
If the script is short enough, you can include it in the AppleScript directly:
do shell script "if [ -f /tmp/foo ]; then rm /tmp/foo; fi"
If it's long and/or complex enough that that's unwieldy, you can embed it in the application bundle (I think in the Contents/MacOS subfolder would be the best place), and then execute it from AppleScript like this:
set objectFolder to (path to me) as string
do shell script ((quoted form of POSIX path of (objectFolder)) ¬
& "Contents/MacOS/scriptname")
I hope this is fairly simple but I'm struggling to get this to work.
I have a java package which I want to execute using a shell script command...
/jdk1.7.0/bin/java .path.to.classname.ClassToExecute >> /var/log/output.log
...so essentially...
./SCRIPT_NAME
...should run the above from the command line.
The problem is there is a classpath update needed every time first from the command line to enable the session to see a particular JAR...
export CLASSPATH=$CLASSPATH:/path/to/jar/file/lib/JAR_NAME.jar:.
If I don't put this line in first the shell script will not execute throwing errors of NoClassDefFoundError relating to the JAR I need to add manually.
Can anyone tell me where I need to edit this classpath update so that it's ALWAYS available to the script and also to the cron as ultimately I want to call it from the cron?
Thanks,
ForestSDMC
Your shell script should look like this.
#!/bin/bash
export CLASSPATH=$CLASSPATH:/path/to/jar/file/lib/JAR_NAME.jar:.
/jdk1.7.0/bin/java .path.to.classname.ClassToExecute >> /var/log/output.log
You also need to change the permissions of the script so that it is executable
chmod 700 SCRIPT_NAME
700 = owner can only execute the script
770 = owner and members of a group can run the script
777 = everyone who has access to the server can run the script.
Noticed that you want to run this from cron. You need to source your .profile either from the crontab entry or from within the script.
Just found the answer and works fine so hopefully others will find this useful...
You can dynamically generate the classpath variable within the shell script and then apply it as an attribute to the java command line execution. Like this...
THE_CLASSPATH=
for i in `ls /path/to/the/JARS/lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
/usr/bin/java -cp ".:${THE_CLASSPATH}" path.to.the.class.ClassName >> /var/log/logfile.log