Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [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
    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. $spacer_open
    $spacer_close
  5. #4
    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
  •