Active Topics

 


Reply
Thread Tools
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#1
Dear All,
I am quite a noob when it comes to Linux. I used to write advanced scripts in Windows Powershell and now I want to do the same in Linux.

The following is a script I wrote but I have no clue on how to make it executable and how can i make an icon for it to launch a script. If someone would be kind to pass a few links, will be helpful for me.

I tried to run this in my N900 and it kinda screwed up the device as I am sure i did somethin wrong. had to reflash it. So would be really honoured if omeone could help a lil so tht I can do my contribution to this forum as well.

Code:
#!/bin/bash
echo **********************************************
echo *           TrueCrypt Assistant              *
echo **********************************************
echo
choice=3
echo Please choose the approriate task.
Echo   1. Mount Crypt Drive.
Echo   2. Unmount all Drives.
while [$choice -eq 3 ]; do
read choice
if [$choice -eq 1 ] ; then
echo Mounting Crypt Drive. you may be asked for authorization password.
truecrypt -k "" --protect-hidden=no /media/mmc1/TrueCrypt /media/Crypt
tracker-processes -r
exit
else
if [$choice -eq 2 ] ; then
echo Unmounting all Crypt Drives.
truecrypt -d
tracker-processes -r
exit
else
echo Please choose either "1" or "2".
fi
fi
done
Does Linux Scripts support GOTO and Labels? Also I had referred a few sites over google to come up with this.. Hope someone helps with corrections.

Last edited by fareed_xtreme; 2010-12-07 at 06:11.
 
Posts: 486 | Thanked: 251 times | Joined on Oct 2009
#2
Originally Posted by fareed_xtreme View Post
The following is a script I wrote but I have no clue on how to make it executable and how can i make an icon for it to launch a script. If someone would be kind to pass a few links, will be helpful for me.
Code:
chmod +x filename
makes a file executable. The file system needs to be mounted with the exec option. The Mydocs partition is mounted noexec by default, so your script should be stored someplace else if it is on Mydocs.
Originally Posted by fareed_xtreme View Post
Does Linux Scripts support GOTO and Labels? Also I had referred a few sites over google to come up with this.. Hope someone helps with corrections.
For elaborate logic flow, you might want to consider perl or python. perl can invoke OS commands with
Code:
system "command options arguments";
or
Code:
`command options arguments`;
__________________
The Mini-USB plug is an improvement over both the Type B plug and the Micro-B plug.
 

The Following 2 Users Say Thank You to j.s For This Useful Post:
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#3
Originally Posted by j.s View Post
Code:
chmod +x filename
makes a file executable. The file system needs to be mounted with the exec option. The Mydocs partition is mounted noexec by default, so your script should be stored someplace else if it is on Mydocs.


For elaborate logic flow, you might want to consider perl or python. perl can invoke OS commands with
Code:
system "command options arguments";
or
Code:
`command options arguments`;
Thanks a lot for your assistance on this. I wil try it out in a few minutes and hope I can get it to work.
 
Posts: 136 | Thanked: 150 times | Joined on Dec 2010 @ Finland
#4
Originally Posted by fareed_xtreme View Post
Thanks a lot for your assistance on this. I wil try it out in a few minutes and hope I can get it to work.
If you do get it working, would you mind posting your final script here for the general public, as this could be something that would make Truecrypt usage a lot easier for the general N900 user base?
 
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#5
Originally Posted by mooglez View Post
If you do get it working, would you mind posting your final script here for the general public, as this could be something that would make Truecrypt usage a lot easier for the general N900 user base?
Well I have been waiting for someone to create some script for a long time as typing each time was a headache for me. lol. Then I realised why not give it a try. Well lets see how it turns out.
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#6
Hi fareed_xtreme,

Here some example code that might be useful to you.

To make a selection menu:

Code:
#!/bin/sh

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "MENU"
    echo "1 - first command"
    echo "2 - second command"
    echo "3 - third command"
    echo ""
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        0) exit ;;
	1) cd /home/user/;;
	2) ls -al;;
	3) ssh user@192.168.0.3;;
	*) echo "Please enter 1, 2, or 0"
    esac
done

The .desktop file should be put here:
Code:
/usr/share/applications/hildon/myScript.desktop
and the contents should look like this:
Code:
[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=myScript
Exec=/usr/bin/osso-xterm "/home/user/myscripts/myScript.sh"
Icon=terminal
X-Osso-Type=application/x-executable
Good luck.
 

The Following 2 Users Say Thank You to Saturn For This Useful Post:
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#7
Originally Posted by Saturn View Post
Hi fareed_xtreme,

Here some example code that might be useful to you.

To make a selection menu:

Code:
#!/bin/sh

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "MENU"
    echo "1 - first command"
    echo "2 - second command"
    echo "3 - third command"
    echo ""
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        0) exit ;;
	1) cd /home/user/;;
	2) ls -al;;
	3) ssh user@192.168.0.3;;
	*) echo "Please enter 1, 2, or 0"
    esac
done

The .desktop file should be put here:
Code:
/usr/share/applications/hildon/myScript.desktop
and the contents should look like this:
Code:
[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=myScript
Exec=/usr/bin/osso-xterm "/home/user/myscripts/myScript.sh"
Icon=terminal
X-Osso-Type=application/x-executable
Good luck.
Just the thing I was searching for. Now Iet me get my lazy *** to work. :P maybe in a week or so ill try to get something ready :P
 
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#8
I noticed something Wierd. As I am running the script, the i get the following error

Code:
permission denied.
I have already run the following command as root as well as user.

Code:
chmod +x Filename.sh
Just as a trial I also ran

Code:
chmod 777 filename.sh
No errors while running these commands but on running script, it says permission denied.

Also the desktop file I had created had some problem and so i deleted it but in the menu, the icon still exists. What am i doing wrong here? How can I remove the icon and all?

Last edited by fareed_xtreme; 2010-12-07 at 07:44.
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#9
Maybe the permision denied comes from what you executed inside the script?
Can the commands you've put in the script be executed as user?

Use "ls -al" to view what priviledges you have set to a file.
Make a reboot and see if it is rmoved from the menu.
 
fareed_xtreme's Avatar
Posts: 238 | Thanked: 291 times | Joined on Mar 2010 @ London, UK
#10
Originally Posted by Saturn View Post
Maybe the permision denied comes from what you executed inside the script?
Can the commands you've put in the script be executed as user?

Use "ls -al" to view what priviledges you have set to a file.
Make a reboot and see if it is rmoved from the menu.
I have done the above. The functions inside the script are all executable as a user. i have done a full walkthrough of the script before i started the actual coding process. I just checked them all again and they work just fine if individual commands are given.

Secondly I rebooted 2 times already and still the icon still exists... I do not know what is the issue regarding. and really wish that you could assist me in cleaning this up without the need to format...
 
Reply


 
Forum Jump


All times are GMT. The time now is 13:33.