Autostart messenger, any ideas

Discussion in 'Linux' started by aja22, Sep 25, 2008.

  1. aja22

    aja22

    Joined:
    Sep 25, 2008
    Messages:
    5
    Likes Received:
    0
    hello,
    bought an aspire one with linpus so the missus would leave mine alone, and with reading these forums, have setup VLC added the login window and allowed the menu on right click option, ive also got the built in messenger app starting on boot, however it always starts before the wireless connects, which gives a "cant Connect" error, can anyone provide/point me in the direction of a workaround, please bear in mind ive only dabbled in the basics, of linux (dual boot ubuntu on mine) but im not adverse to trying new things
     
    aja22, Sep 25, 2008
    #1
  2. aja22

    akeyes

    Joined:
    Sep 25, 2008
    Messages:
    12
    Likes Received:
    0
    Hi there,

    The easiest option would be to create a script that will rum the IM client but only after a short delay (I'm assuming you've got access to the terminal for this example)
    e.g
    create a file called /home/user/im_delay.sh
    inside it put the following...

    Code:
    #!/bin/bash
    sleep 20;
    /usr/acer/bin/UIM
    Then make the file executable
    Code:
    chmod 755 /home/user/im_delay.sh
    from the terminal

    From command line load up the autostart editor...
    Code:
    xfce4-autostart-editor 
    Click Add, enter a suitable Name for this startup item and in the Command text box enter
    Code:
    /home/user/im_delay.sh
    Restart your Acer and there will be a 20 second delay before the IM client is started, if your network hasn't connected in that 20 seconds just increase the value for the sleep command in the script and try again

    It's a bit crude but fairly effective ;) , with a little bit of tweaking you could adapt the script to actually check that you're connected to a network before loading up the IM client. If you want to do this, let me know and I can give you a sample script.

    Hope this helps.
     
    akeyes, Sep 27, 2008
    #2
  3. aja22

    aja22

    Joined:
    Sep 25, 2008
    Messages:
    5
    Likes Received:
    0
    scripts are new to me, but this is the best way to learn.......thanks, i'll give it a go.
     
    aja22, Sep 27, 2008
    #3
  4. aja22

    aja22

    Joined:
    Sep 25, 2008
    Messages:
    5
    Likes Received:
    0
    worked.....20 seconds is a bit long but that might change as i add more,

    i was trying to put the "sleep" command directly after the UIM in the autostart manager ie the autostart manager command was "UIM sleep 15", my own warped perception of how it should work
     
    aja22, Sep 27, 2008
    #4
  5. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Hi

    Can't seem to get this to work and as a complete newcomer to linux I imagine it's something I'm doing wrong!! Are you creating a file or a folder which you're placing the script in? If I create a file and try and try and put the script in that, I get a message about downloading a patch (which it subsequently won't let me). If I create a folder, open a terminal from within it and put the script there I don't appear to be getting any success.

    Any ideas?

    Cheers
     
    leaky74, Nov 24, 2008
    #5
  6. aja22

    markh

    Joined:
    Oct 6, 2008
    Messages:
    299
    Likes Received:
    0
    A useful tip I found in this thread: http://www.aspireoneuser.com/forum/view ... ssh#p30761 was that by placing your script in /etc/NetworkManager/dispatcher.d/ and making it executable as above (but not using the autostarter), it will be executed once network manager has found a connection, provided you add a little extra to your script:
    Code:
    #!/bin/sh
    if [ "$2" = "up" ]; then
        /usr/local/sbin/GCALDaemon/bin/standalone-start.sh
    fi
    Obviously you replace my /usr/... line with your own. (Edit: see later post by mjdell about how to fix a couple of problems with adapting this to run a mainstream application like messenger)

    @leaky, the folders referred to already exist, but the files need creating. Typing mousepad "filename" in a terminal called to the folder should do the trick (you'd need sudo mousepad in despatcher.d).
     
    markh, Nov 24, 2008
    #6
  7. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Thanks for the reply Mark; apologies, like I say this is v. new to me. I can right mouse and create a document anywhere within a folder structure - are we differentiating between folder, file & document? You'll have to presume I know nothing in terms of interacting with linux!
     
    leaky74, Nov 25, 2008
    #7
  8. aja22

    markh

    Joined:
    Oct 6, 2008
    Messages:
    299
    Likes Received:
    0
    Ok, Linux shares the basic directory/file idea as windows. So for /home/user/im_delay.sh, that's directory home, sub dir user, and then file im_delay.sh. It's the same as, say, C://Windows/Program Files/filename.doc on windows. The major differences are that linux doesn't use C: or B: or whatever for drives, but just starts with a /., and that it's not so bothered about file extensions (in filename.doc, the .doc is the file extension).
    The thing about linux is that any graphical interface, like the file manager, is simply manipulating the text-based system that underlies linux on your behalf. So in the same directory, right clicking and opening a terminal will give you an interface where you're already changed into that directory (you'll see the directory name in your prompt). Type ls, and it will list the contents of your directory for you, for example. So if you're using the file manager, and you right click to create a document, that is creating a file. Once you've created it, another right-click ought to give an option to edit with mousepad (which is just a quick and easy text file editor).
    Anyway, the point of all of that was to say that there is absolutely no difference between doing things with the mouse in file manager, and doing things in the terminal. It's just the terminal is less friendly, and often more powerful. So mousepad xyz in the terminal gets you file xyz in mousepad, and right-click, create, then right-click, edit with mousepad gets you too exactly the same place.
    Anyway, I've rambled there. Hope that helped in some way, and wasn't telling you to suck too many eggs.
     
    markh, Nov 25, 2008
    #8
  9. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Mark

    Thanks for taking the time to reply again - much appreciated; apologies again for me being slow on the uptake here!! Right getting there; just one issue - I'd really like to achieve what you're suggesting with your script however, if I RMB within /etc/NetworkManager/dispatcher.d/ the option to create is greyed out.

    Presuming you can advise what the issue here is, what exactly would the script look like to auto exec the messenger upon network detection.

    You wouldn't believe it but I do work in IT!!! (Not a techie though - Business Analyst on ERP Maintenance Management & Supply Chain Solutions). I leave this stuff to the people who know what they're doing!!
     
    leaky74, Nov 25, 2008
    #9
  10. aja22

    mjdell

    Joined:
    Nov 23, 2008
    Messages:
    2
    Likes Received:
    0
    I tried to follow the instructions in this thread, but hit a couple of problems, so I thought I'd share what they were and how I resolved them, in case anyone else is seeing similar issues.

    Firstly, I realised that the script as run by the dispatcher doesn't have any kind of path set up, so you need to define the path you need before executing the commands themselves.

    Secondly, the script is run as root, which means when you start UIM, you get root's account list etc, which probably isn't what you want.

    I resolved these issues as follows:

    1. Add a script to the dispatcher.d directory, which looks like this:

    Code:
    #!  /bin/bash
    if [ "$2" = "up" ]; then
    sudo -u user /home/user/startmyuim.sh
    fi
    
    This runs the script startmyuim.sh, as the standard user "user", rather than as root. Ensure you write this file as root (so edit it by running "sudo mousepad /etc/NetworkManager/dispatcher.d/uimstarter.sh").

    2. Add a script /home/user/startmyuim.sh which looks like this:

    Code:
    #! /bin/bash
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/acer/bin:/sbin:/usr/sbin:/home/user/bin
    UIM
    
    This script just ensures you have the right path set up, and then executes the UIM script. This file should be owned by "user", so create it by just running "mousepad ~/startmyuim.sh". You then need to chmod 755 this file too.

    Hope this is useful to someone else, as it took me 1.5 hours to work all this out.
     
    mjdell, Nov 26, 2008
    #10
  11. aja22

    markh

    Joined:
    Oct 6, 2008
    Messages:
    299
    Likes Received:
    0
    Ah, thanks for those improvements. I didn't need either part for my particular script (I was using the full path, and running as root doesn't harm my app), so I simply hadn't run into either problem. I'll edit my post to point down to yours. I wonder if this is worthy of writing up as a how-to?
     
    markh, Nov 26, 2008
    #11
  12. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Hi

    Thanks for everyones continued input - a how to guide would be good. Sorry to harp on but a descriptive step by step (idiots!) guide would be even better for the clueless amongst us i.e. me!
     
    leaky74, Nov 26, 2008
    #12
  13. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Guys

    Sorry to hassle - any chance of the complete noob (big) idiots guide to setting this up - I'll pretty much have the set up I want if I can get this working!!
     
    leaky74, Nov 27, 2008
    #13
  14. aja22

    daldred

    Joined:
    Aug 25, 2008
    Messages:
    887
    Likes Received:
    0
    I'll try...

    The guys further up the thread have suggested creating a couple of scripts and puting them into specific places. The issue you may have is that one of the places in question is in an area of the file system which are accessible to the root user, not to you!

    The easy way round this is to use sudo, which lets you do things as though you were root. But... you really need to use the terminal to become root.

    So, first let's get a terminal: do ALT-F2 and type 'terminal' in the box which comes up, then hit OK.

    Now we'll start Mousepad as root and create that first script. In your terminal, type
    Code:
    sudo mousepad /etc/NetworkManager/dispatcher.d/uimstarter.sh
    To explain: sudo makes you work as root temporarily, mousepad is the editor, and the rest is the full path and name of the file you're creating. You see that red warning at the top of the Mousepad window? Doing things as root can be dangerous!

    Now into this mousepad window type the following (or copy & paste from here):
    Code:
    #!  /bin/bash
    if [ "$2" = "up" ]; then
    sudo -u user /home/user/startmyuim.sh
    fi
    Explanation: this is a script, a set of instructions which will be executed by the system when the Network Manager decides to do so - that's why it's going into the NetWorkManager/dispatcher.d directory. The first line tells it what program to use to interpret it (the 'bash' shell), the second tells it to act if the second argument is "up" - mjdell would have to explain *why* that particular phrasing works! - and the third line is what it does - it calls another script we are about to create. The 'fi' closes the 'if' like a pair of brackets round part of a sentence.

    Now we need to make that script 'executable'. In Linux, you can execute any file at all, whatever its name - it doesn't need to end in exe, bat or com as Windows expects. However, you have to explicitly make the file executable. If you're installing from a package that is handled as part of the deal; if you're making your own scripts you have to do it yourself.

    To make our new script executable, in the terminal type:
    Code:
    sudo chmod 755 /etc/NetworkManager/dispatcher.d/uimstarter.sh 
    sudo you'ver seen before; chmod is changing the mode of the file. Modes are not all that complicated, but better explained elsewhere (google "linux file modes" - the first hit I got was good!) - the '755' are the modes you want applied to your shiny new file.

    Now save the file and close your mousepad editor. While we're using the terminal, though, let's use it for the other script - this time we don't need sudo as the script is going into your home directory. Do:
    Code:
    mousepad /home/user/startmyuim.sh
    You don't need sudo this time: you're in your own home area. You know what mousepad is - getting good at this, aren't you? You don't actually need the /home/user either: by default you are in your own home directory when you start a terminal.

    In the mousepad window (no red bar this time - you're not root) type or copy'n'paste:
    Code:
    #! /bin/bash
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/acer/bin:/sbin:/usr/sbin:/home/user/bin
    UIM
    
    Another script. First line - as last time. Second - sets up the path, the locations where your script will look for any commands; this may not be necessary but is safe. Third line: starts the UIM program, which is what you wanted to happen when we started all this.

    Save the file, close the mousepad, and then use the terminal to make this executable too:
    Code:
    chmod 755 /home/user/startmyuim.sh
    You shouldn't need that explaining by now!

    Now when you start your machine, the Network Manager will finish setting up your connection, notice it's got another script to run, run it and tell the UIM to start - and you're away.

    Welcome to the wonderful world of Linux scripting. You've just entered and set up your first two Bash scripts. Fun, wasn't it? No, you are not yet a fully fledged Linux hacker! :)
     
    daldred, Nov 27, 2008
    #14
  15. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    David

    Perfect approach - this is exactly how I compile user guides for engineering systems; simple steps & screen grabs. I understand what we're doing here now however I get the following message when trying to make the script executable;

    chmod: cannot access `/etc/NetworkManager/dispatcher.d/uimstarter.sh': No such file or directory

    Nearly there, just need a little more coaxing......
     
    leaky74, Nov 27, 2008
    #15
  16. aja22

    markh

    Joined:
    Oct 6, 2008
    Messages:
    299
    Likes Received:
    0
    David, thanks for the guide - I was a bit busy at work today to respond as I'd planned.

    Leaky, did you catch that there was an accidental double "sudo mousepad" in the first cut-and-paste? If you didn't, then you'll have created a file called sudo, which is why chmod didn't find it. If you had caught that, then I'm unsure what's happened - you may wish to double check spelling, cases, etc.
     
    markh, Nov 27, 2008
    #16
  17. aja22

    daldred

    Joined:
    Aug 25, 2008
    Messages:
    887
    Likes Received:
    0
    Could be my fault; in the first set of instructions I told you to do
    Code:
    sudo mousepad sudo mousepad /etc/NetworkManager/dispatcher.d/uimstarter.sh
    That should read
    Code:
    sudo mousepad /etc/NetworkManager/dispatcher.d/uimstarter.sh[
    If you actually did exactly what I said, you've created a file called sudo in your own home directory instead of the file I wanted you to create!

    If you have done this, the quicker way to get it to wher it's meant to be is to move it there: again in the terminal do
    Code:
    sudo mv /home/user/sudo etc/NetworkManager/dispatcher.d/uimstarter.sh/
    ..then do the chmod instruction again and it should work.

    I've edited my previosu post so as not to confuse anyone else!
     
    daldred, Nov 27, 2008
    #17
  18. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    :D Wow you guys - nailed it! You're right - the cut & paste had created the file "sudo" in home drive!

    Don't know if it makes a difference or not but at the point when you run the first exe command you don't get a prompt in the terminal until you close the mousepad - the one you're in as root with the first script. I had to save and close that mousepad before I got the prompt back in the terminal - if that makes sense??

    Thanks again guys; very much appreciative of your time and efforts!!! :D
     
    leaky74, Nov 27, 2008
    #18
  19. aja22

    daldred

    Joined:
    Aug 25, 2008
    Messages:
    887
    Likes Received:
    0
    Great: glad it works.

    If you run a command from the terminal, the terminal waits for that command to finish before taking any more input (except input for the program you've just run) - that's why you don't get a prompt back until you've closed mousepad. You can run mousepad in the background instead - try doing
    Code:
    mousepad &
    where the & at the end tells the terminal to make it a background task. Now you'll get a prompt straight away: the terminal is able to work on other 'foreground' tasks.

    Many programs run from the terminal in this way will close if the terminal is closed, though, so you can run the risk of losing work if you close the terminal, forgetting it's running a background task - and any error messages generated by background tasks still go to the terminal, and can interrupt what you're doing there.
     
    daldred, Nov 27, 2008
    #19
  20. aja22

    leaky74

    Joined:
    Nov 18, 2008
    Messages:
    8
    Likes Received:
    0
    Thanks again guys - you've achieved guru like status in my eyes!! I've even managed to install konquerer in order to view my home network (which seems like a sledgehammer to crack a nut but it's the only approach I could get to work!).

    I'll be sure to apply the messenger auto exec script to the wife's AAO - she may even be impressed!!!
     
    leaky74, Nov 28, 2008
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.