Announcement

Collapse
No announcement yet.

How to create a konsole batch file?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to create a konsole batch file?

    Hello all,
    I'm very new to linux and kubuntu, started using for work, so far it's been great. For work we have to initiate some of the software we're using via the Konsole, 99% of them are one command after another, so I'd like to find out if there is a way to create single file equal to a windows .bat file, where I can make my own shortcuts to initiate the software.

    In essence:

    1. Run command X
    2. Wait a few sec, (because command X is initiating the environment I need to be on)
    3. Run command Y (leave konsole window open after.

    Thanks in advance!







    #2
    There are hundreds, if not thousands, of manuals on the web giving tutorials on how to create bash scripts.
    Here is just a simple one:https://www.freecodecamp.org/news/sh...ipts-in-linux/
    Once you get into it you'll need a more complete manual, explaining in depth the bash scripting language.
    Here is one of hundreds: https://www.gnu.org/software/bash/manual/bash.pdf

    The bash program on your system contains a man (manual) page. You can open an Konsole and enter "man bash" and it will be displayed. You can scroll forward and backward through it. Hit the "Q" key to close the manual. If you want to search for a specific term you can use "man bash | grep someterm"
    and only the lines containing that term will display.

    Bash scripting is a LOT of fun, so have fun and good luck!
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.

    Comment


      #3
      What GreyGeek said, especially about the fun.

      I'd like to add:
      1. There are many, many, ways to do scripting on Linux. Using bash is a good start, though. Scripts are not tied to konsole; konsole let's you run bash interactively, which is helpful to suss out the commands. I have scripts I use a lot as menu items, or widgets on a panel.
      2. We're really helpful here on kubuntuforums.net, particularly when it comes to scripting. When posting about scripts it's a good idea to put scripts or output in code tags; you can type them, or use the # button.
      Regards, John Little

      Comment


        #4
        Originally posted by jlittle View Post
        1. There are many, many, ways to do scripting on Linux. Using bash is a good start, though. Scripts are not tied to konsole; konsole let's you run bash interactively, which is helpful to suss out the commands. I have scripts I use a lot as menu items, or widgets on a panel.
        2. We're jlittle is really helpful here on kubuntuforums.net, particularly when it comes to scripting. When posting about scripts it's a good idea to put scripts or output in code tags; you can type them, or use the # button.
        There - fixed it for ya! LOL

        Please Read Me

        Comment


          #5
          Originally posted by cowabungaRaf View Post
          Hello all,
          I'm very new to linux and kubuntu, started using for work, so far it's been great. For work we have to initiate some of the software we're using via the Konsole, 99% of them are one command after another, so I'd like to find out if there is a way to create single file equal to a windows .bat file, where I can make my own shortcuts to initiate the software.

          In essence:

          1. Run command X
          2. Wait a few sec, (because command X is initiating the environment I need to be on)
          3. Run command Y (leave konsole window open after.

          Thanks in advance!
          Yes to all that and ditto to what my colleagues said above. Welcome to the forum.

          I suppose to directly answer your question:
          1. Open Kate
          2. Start with #!/bin/bash as the first line
          3. Add commands and fun stuff
          4. Save the file somewhere
          5. Make it executable
          6. Run it

          Last edited by oshunluvr; Mar 20, 2023, 03:44 PM.

          Please Read Me

          Comment


            #6
            Originally posted by oshunluvr View Post
            […]
            4. Save the file somewhere …
            […]
            I would add:
            … with no file extension, a .sh file extension (most people do that) or a .bash file extension if you use the "standard" Linux Bash shell.
            I personally prefer the latter two variants to recognise the file type at a glance.
            Last edited by Schwarzer Kater; Mar 20, 2023, 08:30 PM.
            Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
            Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

            get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
            install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

            Comment


              #7
              Originally posted by Schwarzer Kater View Post

              I would add:
              … with no file extension, a .sh file extension (most people do that) or a .bash file extension if you use the "standard" Linux Bash shell.
              I personally prefer the latter two variants to recognise the file type at a glance.
              Agreed - no extensions used here. It is a common Windows user thing to need to add an extension to every file. I simply don't bother. I believe this was a "crutch" requirement created by MS because they assume their users need crutches, Or maybe I made that up, lol.

              I will say that I work in a multi-shell environment - csh, tcsh, and bash - and the .sh extension is commonly used in all of them. I suspect that it's common meaning is "this is a shell script" extension. Although that is something I surmised given my experience and not via any documentation. Since the shebang dictates which interpreter is called, which shell language is used doesn't need indication from a file extension - at least in my world.

              Please Read Me

              Comment


                #8
                Here is an example of a bash script I wrote recently when I returned to Kubuntu. It uses HDSentinel to query the state of SSD's using S.M.A.R.T. and displaying the results using my web browser, which is FireFox 111.0.

                I titled it "check_ssd_status.sh"
                Code:
                #!/bin/bash
                #
                # script to check status of SSD drives.
                #
                
                NOW=$(date +%Y%m%d%H%M)
                cd /home/jerry/Downloads/HDSentinel_GUI
                sudo /home/jerry/Downloads/HDSentinel_GUI/HDSentinel -html -r ssd_state_${NOW}.html
                firefox ssd_state_${NOW}.html
                quit
                You can download the free Linux version of HDSentinel here: https://www.hdsentinel.com/hdslin/hdsentinel-019b.gz

                The "-html" parameter tells it to make the report an HTML page. The "-r" parameter tells it to generate that report using the supplied name. The HTML page is dated and saved in that directory for future reference. Each one uses abougt 40Kb.

                I used an icon from the website and made a menu entry so all I have to do is click on it and enter my sudo password when prompted.
                Last edited by GreyGeek; Mar 22, 2023, 03:23 PM. Reason: Forgot last line in script...
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #9
                  Hello All,

                  Sorry I've been gone, thanks so much for all the info, I certainly already had some fun, I managed to get my simple shortcut working, but I see there is a lot more to learn here. But instead of experimenting on my work computer I have installed the same Kubuntu linux I have at work in a separate HD i had and I'll play around more.

                  Much appreciated all the quick and in depth replies, much better than searching random posts in google.

                  Comment


                    #10
                    My personal favorite is the "Advanced Bash-Scripting Guide" from the linux documentation project... YMMV.
                    Available at: https://tldp.org/LDP/abs/html/

                    cheers,
                    bill
                    sigpic
                    A person who never made a mistake never tried anything new. --Albert Einstein

                    Comment


                      #11
                      And, there is another tool that I recommend. For $10/mo you can use GPT-4 to help your both lean and code bash scripts.
                      https://openai.com/blog/chatgpt

                      PS-
                      For grins and giggles I submitted a question to GPT-4 asking it what is the best resource to use to learn bash scripting. Here is its answer:
                      There are many resources available online to learn how to write bash scripts. Here are some of the best ones:

                      Bash Academy (https://www.bash.academy/) - This website offers a comprehensive tutorial on bash scripting, starting from the basics and going all the way to advanced topics. It includes interactive exercises and quizzes to help you practice what you learn.

                      Linux Documentation Project (https://tldp.org/LDP/abs/html/) - The Advanced Bash-Scripting Guide is a great resource for those who want to learn bash scripting in depth. It covers topics such as variables, loops, functions, and more.

                      Bash Reference Manual (https://www.gnu.org/software/bash/manual/) - This is the official reference manual for bash scripting. It is a comprehensive guide to all aspects of bash scripting, from basic syntax to advanced features.

                      Udemy (https://www.udemy.com/topic/bash-scripting/) - Udemy offers a variety of courses on bash scripting, from beginner to advanced levels. These courses are usually created by industry experts and provide hands-on practice.

                      YouTube (https://www.youtube.com/results?sear...pting+tutorial) - YouTube is a great resource for visual learners. There are many tutorial videos available that cover different aspects of bash scripting.

                      Regardless of which resource you choose, it's important to practice writing bash scripts on your own. Start with simple scripts and gradually build up to more complex ones. The more you practice, the more comfortable you will become with bash scripting.
                      Last edited by GreyGeek; Apr 01, 2023, 11:42 AM.
                      "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                      – John F. Kennedy, February 26, 1962.

                      Comment

                      Working...
                      X