Find the answer to your Linux question:
Results 1 to 4 of 4
Can someone help me write some simple script? Hereís what Iím trying to do: - Qjackctl has a config file which is modified each time QjackCtl is shut down. This ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    7

    [SOLVED] Please help me write a Shell Script which edits a Config file


    Can someone help me write some simple script? Hereís what Iím trying to do:

    - Qjackctl has a config file which is modified each time QjackCtl is shut down. This means that whatever preset is in use when QjackCtl closes is written into the QjackCtl config file as the DEFAULT PRESET, for the next time QjackCtl starts (or at least this is how I understand it).

    - I want to edit a specific line in the QjackCtl.config file, which specifies the DEFAULT PRESET. Obviously itís easy to do manually, but I want to do it using a shell script which runs automatically on StartUp so that QjackCtl starts every time with the same DEFAULT PRESET, NOT the last one used.

    - Unfortunately Iím not at my Linux system right now (which is KXStudio/Kubuntu), but I believe the QjackCtl.config line looks something like this:
    DEF_PRESET=alsa (where ďalsaĒ is the name of the preset)
    PRESET1=alsa
    PRESET2=firewire


    I want a shell script which changes the line ďDEF_PRESET=alsaĒ to ďDEF_PRESET=alsaĒ, even when it may currently exist as ďDEF_PRESET=firewireĒ due to occasions when ďfirewireĒ was the active preset when Qjackctl was last closed. I notice that the application in KDE that enables the user to set which applications open automatically on StartUp also allows the user to select shell scripts.

    Iíve done some research, as a beginner, and Iím led to believe I might need to use AWK and/or CHMOD. I could have a go at writing a shell script but Iím always wary about experimenting with StartUp scripts/operations because obviously if I get it wrong and make my system unusable, then because itís going to run first thing on each boot, Iíd have great difficulty disabling it.

    Any help or advice hugely appreciated! Remember Ė Iím a beginner looking to gain an understanding. But if anyone feels like writing the script for me I wonít object .

  2. #2
    Just Joined!
    Join Date
    Mar 2007
    Location
    BogotŠ, Colombia
    Posts
    46
    This is a very straight forward way to do it:

    Code:
    #!/bin/bash
    
    CFGFILE=/your/config/file
    TEMPFILE=/some/temp/file
    
    sed -r 's/DEF_PRESET=.*$/DEF_PRESET=alsa/' $CFGFILE > $TEMPFILE
    mv $TEMPFILE $CFGFILE
    just replace the definitions for your files, i do suggest to use a rather strange temp file to no screw things up, like "/var/tmp/your-temp-file.cfg" or something like that, something that doesn't exists

  3. #3
    Just Joined!
    Join Date
    Feb 2011
    Posts
    7
    Hey thanks LSalab! Looks good. I'll give it a spin shortly when I'm back on Kubuntu and let you know how it went.

  4. #4
    Just Joined!
    Join Date
    Feb 2011
    Posts
    7
    SOLVED!

    After experimenting with various suggestions I decided to take a different approach. Rather than trying to edit the QjackCtl config file so that the "DefPreset" (default preset) was reset back to "alsa" each time the system starts up, I remembered a command someone in the Linux-Audio-User mailing list suggested:

    Code:
    qjackctl -p alsa
    "Start QjackCtl with the preset called 'alsa'"

    Surely it would be too simple to simply put just this in the shell script file, but I gave it a shot and it works!!!!

    The QjackCtl config file does still show whatever the last used preset in QjackCtl was as being default, but it now doesn't necessarily load it. Instead it always starts QjackCtl with the preset "alsa". For anyone else wanting to use this method, make sure you do the following:

    - Get rid of any previous settings which cause QjackCtl to startup automatically on system startup.
    - The above script is the only auto-start command needed and it should go in a shell script file which is specified in "Autostart", and set the "Run On" option to "Startup", not "Shutdown" or Pre-KDE startup".
    - In QjackCtl settings, you can enable "start JACK audio server connection on application startup" to not only have QjackCtl load with a particular preset, but to start the audio server straight away, seamlessly with that preset too.
    - My preset is called "alsa". Remember to change that to whatever you named your desired default preset as.

    Hope this helps someone else!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •