1

I have a bash script which I want to start with arguments by an app. Currently I can generate the command, but how can I execute it? This app is for jailbroken phones only. Any solutions for this? I searched a lot, but didn't found anything.

1 Answer 1

3

If this is a jailbreak app, you can run the command by passing it to the system() function that's part of the OS, or one of the exec functions.

So, if you decide to install your script at /Applications/MyApp.app/myscript.sh, then in your app, you could use:

int result = system("/Applications/MyApp.app/myscript.sh argument1 argument2");

You can install the script as I've shown, in your app's folder, as a resource, or in /usr/bin, or /bin, or wherever you like.

You don't mention whether or not you're installing your app in /Applications, as most jailbreak apps are, or in the normal /var/mobile/Applications/* locations.

If the above code doesn't work, please clarify where you want to install your app. Also, depending on whether or not your script requires root privileges, there may be more work necessary. There are some complications if you want to run a shell script as root.

Sign up to request clarification or add additional context in comments.

12 Comments

so, the app is installed as a normal app and in /Application/MyApp.app/ the script does not require root I tried it with system() but it didn't worked
What went wrong? system() returns an error code result. What was the error code? Did you remember to make your sh script executable with chmod? Login to the phone and do an ls -al /Applications/MyApp.app/ and let us know what the permissions look like on your script. Thanks.
the script is downloaded from cydia, as a library and can be executed everywhere, the system returned 32512
Your first comment isn't quite clear. If you install an app as a normal application, then it will not be in /Applications. It will be under /var/mobile/Applications. Which one is it? Also, you didn't answer my question about the permissions on your script. Is your script executable, after it has been deployed to your device? Can you run it directly from the command line?
There's many ways to do that. If you have terminal/shell access, you can just ssh into your device. cd to /var/mobile/Applications/ and do find . -name MyAppName.app. This will find where your app is installed. Then just copy the whole MyAppName.app folder to /Applications. For example, after changing to the proper directory, cp -Rp ./MyAppName.app /Applications/. You might then want to uninstall the original version, or else you're going to see two identical icons. Reboot, or restart springboard, or use su mobile -c uicache to force springboard to see the new app. Done.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.