Command completion suggestions while typing?
How to get the behaviour of when I type in say,
https://redd.it/1j6o5zg
@r_bash
How to get the behaviour of when I type in say,
lo or lon, a faded g_cmd appears after the cursor (for a command long_cmd), which after pressing <TAB>, gets un-faded/is written to the input line? I tried looking but couldn't really find anything. I just got fzf, it provides completion but only after you type in a command. TIA.https://redd.it/1j6o5zg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
HELP Please. The while loop is running before SSH has ended completely.
https://preview.redd.it/6yv2drjx0ine1.png?width=687&format=png&auto=webp&s=afaef25c281cf083cbc5685e7552203ef6375e58
https://preview.redd.it/f622kvze1ine1.png?width=596&format=png&auto=webp&s=943b60670c3d4ce0e63d5e143673302c5db97f08
So I wrote this code to automate ssh and storing passwords in OverTheWire challenge.
Problem : When I press Enter nothing happens.
What I think the problem is : The while loop starts running before the SSH ends completely. Even GPT did not help.
Can someone please tell me wat the issue is, and how to fix it?
https://redd.it/1j6lxab
@r_bash
https://preview.redd.it/6yv2drjx0ine1.png?width=687&format=png&auto=webp&s=afaef25c281cf083cbc5685e7552203ef6375e58
https://preview.redd.it/f622kvze1ine1.png?width=596&format=png&auto=webp&s=943b60670c3d4ce0e63d5e143673302c5db97f08
So I wrote this code to automate ssh and storing passwords in OverTheWire challenge.
Problem : When I press Enter nothing happens.
What I think the problem is : The while loop starts running before the SSH ends completely. Even GPT did not help.
Can someone please tell me wat the issue is, and how to fix it?
https://redd.it/1j6lxab
@r_bash
In theory, could all quoting be achieved with just the backlash character? Or are there instances where single quotes are required
In other words, are single quotes supported by necessity or pure convenience?
https://redd.it/1j7jak3
@r_bash
In other words, are single quotes supported by necessity or pure convenience?
https://redd.it/1j7jak3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
exitcode from a pipe inside an if statement
Backstory, SomeCommand produces 15-20 lines of output that the user needs to read. Sometimes it fails, most of the time in a known way.
My approach has been
if [[ `SomeCommand |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then
echo Known error $Xcode
else
echo Unknown error $Xcode
exit
fi
/dev/stderr goes to the console so the user can see the output
grep finds the known error string & handles it correctly
but...
$Xcode is always 0 :(
If $Xcode is >0 and it's not the known error, the noscript should terminate.
Have been using true, false & echo as SomeCommand for testing, maybe this is an issue.
It's not the |tee part
if [[ `false |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then echo found $Xcode; else echo not found $Xcode; fi
not found 0
It's something to do with the if [[ `...` \]\] bit
false |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}; echo $Xcode
0
1
If it's changed to if [...\], then it's always 1
if [ `echo "Known Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Known Error
found 1
if [ `echo "Unknown Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Unknown Error
not found 1
Someone please put me out of my misery.
https://redd.it/1j7q8as
@r_bash
Backstory, SomeCommand produces 15-20 lines of output that the user needs to read. Sometimes it fails, most of the time in a known way.
My approach has been
if [[ `SomeCommand |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then
echo Known error $Xcode
else
echo Unknown error $Xcode
exit
fi
/dev/stderr goes to the console so the user can see the output
grep finds the known error string & handles it correctly
but...
$Xcode is always 0 :(
If $Xcode is >0 and it's not the known error, the noscript should terminate.
Have been using true, false & echo as SomeCommand for testing, maybe this is an issue.
It's not the |tee part
if [[ `false |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then echo found $Xcode; else echo not found $Xcode; fi
not found 0
It's something to do with the if [[ `...` \]\] bit
false |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}; echo $Xcode
0
1
If it's changed to if [...\], then it's always 1
if [ `echo "Known Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Known Error
found 1
if [ `echo "Unknown Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Unknown Error
not found 1
Someone please put me out of my misery.
https://redd.it/1j7q8as
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
New to Bash Scripting and Sysadmin? Check Out My Tool: Linux Console Manager (Open Source - All Feedback Appreciated)
Hi r/bash community!
I'm a new Redditor, and I wanted to share a simple bash noscript I've been working on called Linux Console Manager. I'm actually from Korea and haven't used Reddit much before, but I'm excited to share this with you all!
As someone who occasionally does Linux system administration, I found myself constantly typing the same commands over and over. So, I created this little tool to streamline those common tasks and make my life a bit easier. I thought it might be helpful for others too, especially those who are newer to Linux or just want a quicker way to manage their systems from the terminal.
Key Features:
System Monitoring: Tired of typing top, free -m, df -h, and ifconfig separately? Linux Console Manager gives you a quick, consolidated overview of essential system metrics like CPU usage, memory consumption, disk space, and network stats in one place!
Service Control: Managing system services like Apache, Nginx, or MySQL can be a bit tedious with systemctl. This noscript lets you easily start, stop, restart, and check the status of your services through a simple menu. No more struggling to remember those commands!
Process Management: Quickly identify and manage running processes. Need to find that resource-hogging process? Linux Console Manager helps you easily find and even kill processes directly from the noscript.
Network Utilities: Basic network troubleshooting tools like ping and traceroute are built right in, making it convenient for quick network checks.
\[Add other key features of your noscript here - Be specific! For example:\]
User Management: Easily add, delete, or modify user accounts with simple menu options.
Log Viewing: Quickly access and view common system logs like /var/log/syslog or /var/log/auth.log.
Package Management (Debian/Ubuntu based): Simple interface for updating packages or searching for new ones using apt.
The noscript is completely open source and available on GitHub: https://github.com/forsys02/linux\_console\_manager
https://preview.redd.it/1avm3lnnsune1.png?width=458&format=png&auto=webp&s=25a753e1bb074cbc0dbd4e8f4a93c8caa952de5f
I would love for you to try it out and give me your feedback! I'm really open to suggestions for improvement and new features. Specifically, I'm curious about:
Is the menu structure intuitive and easy to navigate?
Are there any features you think are missing or could be more useful?
Do you find it helpful in your daily system administration tasks?
I'd especially appreciate feedback from both experienced sysadmins and those who are newer to Linux. Let me know what you think!
This is a project I'm working on in my spare time, and I hope it can be helpful to others in the community.
Thanks for checking it out! Happy noscripting! 😊
https://redd.it/1j7x3vj
@r_bash
Hi r/bash community!
I'm a new Redditor, and I wanted to share a simple bash noscript I've been working on called Linux Console Manager. I'm actually from Korea and haven't used Reddit much before, but I'm excited to share this with you all!
As someone who occasionally does Linux system administration, I found myself constantly typing the same commands over and over. So, I created this little tool to streamline those common tasks and make my life a bit easier. I thought it might be helpful for others too, especially those who are newer to Linux or just want a quicker way to manage their systems from the terminal.
Key Features:
System Monitoring: Tired of typing top, free -m, df -h, and ifconfig separately? Linux Console Manager gives you a quick, consolidated overview of essential system metrics like CPU usage, memory consumption, disk space, and network stats in one place!
Service Control: Managing system services like Apache, Nginx, or MySQL can be a bit tedious with systemctl. This noscript lets you easily start, stop, restart, and check the status of your services through a simple menu. No more struggling to remember those commands!
Process Management: Quickly identify and manage running processes. Need to find that resource-hogging process? Linux Console Manager helps you easily find and even kill processes directly from the noscript.
Network Utilities: Basic network troubleshooting tools like ping and traceroute are built right in, making it convenient for quick network checks.
\[Add other key features of your noscript here - Be specific! For example:\]
User Management: Easily add, delete, or modify user accounts with simple menu options.
Log Viewing: Quickly access and view common system logs like /var/log/syslog or /var/log/auth.log.
Package Management (Debian/Ubuntu based): Simple interface for updating packages or searching for new ones using apt.
The noscript is completely open source and available on GitHub: https://github.com/forsys02/linux\_console\_manager
https://preview.redd.it/1avm3lnnsune1.png?width=458&format=png&auto=webp&s=25a753e1bb074cbc0dbd4e8f4a93c8caa952de5f
I would love for you to try it out and give me your feedback! I'm really open to suggestions for improvement and new features. Specifically, I'm curious about:
Is the menu structure intuitive and easy to navigate?
Are there any features you think are missing or could be more useful?
Do you find it helpful in your daily system administration tasks?
I'd especially appreciate feedback from both experienced sysadmins and those who are newer to Linux. Let me know what you think!
This is a project I'm working on in my spare time, and I hope it can be helpful to others in the community.
Thanks for checking it out! Happy noscripting! 😊
https://redd.it/1j7x3vj
@r_bash
i want to put raw code into a variable by utilizing heredoc, but it seems that the outer syntax is interpreting things
what i'm trying to do is make a noscript that would put some boilerplate code into files, so i need raw unexecuted code in a variable.
the smallest example of my problem can be shown with this code:
regardless of which of the 4 combinations of fixes i apply here (having quotes around
as i understand it, it's the outer syntax
is there an elegant solution to this so that i don't have to resort to using echo with lots of character escaping?
https://redd.it/1j8q85k
@r_bash
what i'm trying to do is make a noscript that would put some boilerplate code into files, so i need raw unexecuted code in a variable.
the smallest example of my problem can be shown with this code:
DEFAULT_PROGRAM=$(cat <<'EOF'
\)
EOF
)
echo $DEFAULT_PROGRAM
regardless of which of the 4 combinations of fixes i apply here (having quotes around
EOF or not, and having the inner parenthesis escaped or not), it seems to never output just the raw parenthesis. Either it outputs the escaping character too \), or it errors out by saying:EOF: command not found
syntax error near unexpected token `)'
`)'
as i understand it, it's the outer syntax
$(cat ... ) that breaks it.is there an elegant solution to this so that i don't have to resort to using echo with lots of character escaping?
https://redd.it/1j8q85k
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What is the purpose of /dev/tty ?
Please hear me out. So, reading about special devices like tty, tty0, pst1...pstn I understand in loose terms that terminal emulators (like the ones you bring up with ctrl+t ) are special devices under /dev/pts/<some_number> . Now, tty0 appears to be a terminal associated to kernel itself (I still don't know what that means). But tty? I only know that it points to the current terminal being used but I don't know exactly what to make of that and how it pertains to the following humble little snippet I wrote:
#!/bin/bash
while read -r filename
do
echo "Current fie: ${filename}"
read -p "Delete ${filename} ? " response < /dev/tty
if [[ $response = 'y' || $response = 'Y' ]]
then
echo "response was yes"
echo "Deleting ${filename}"
tar vf pdf_files.tar --delete "${filename}"
echo
else
echo "skipping"
fi
done < <(tar tf pdf_files.tar)
You'll notice that in the line that contains the read -p command I had to redirect input from tty. I had chatGPT suggest that to me after many failed attempts at getting my little noscript to run correctly because I didn't understand why $response variable would be automatically set to something and the noscript wouldn't even wait at the prompt for me to enter something. I had my eyes OPENED today -- and in a frustrating way -- as to how many little tricks and things one must take into account when learning bash noscripting.
So, going back to the noscript, why did I even need to do that or more importantly, WHEN do I need to do that kind of trick again?
p.s. I've been learning from time to time bash noscripting for like the past 3 o 4 months and I know I have to learn a lot more, but Jesus, the journey feels never-ending.
https://redd.it/1j98bb0
@r_bash
Please hear me out. So, reading about special devices like tty, tty0, pst1...pstn I understand in loose terms that terminal emulators (like the ones you bring up with ctrl+t ) are special devices under /dev/pts/<some_number> . Now, tty0 appears to be a terminal associated to kernel itself (I still don't know what that means). But tty? I only know that it points to the current terminal being used but I don't know exactly what to make of that and how it pertains to the following humble little snippet I wrote:
#!/bin/bash
while read -r filename
do
echo "Current fie: ${filename}"
read -p "Delete ${filename} ? " response < /dev/tty
if [[ $response = 'y' || $response = 'Y' ]]
then
echo "response was yes"
echo "Deleting ${filename}"
tar vf pdf_files.tar --delete "${filename}"
echo
else
echo "skipping"
fi
done < <(tar tf pdf_files.tar)
You'll notice that in the line that contains the read -p command I had to redirect input from tty. I had chatGPT suggest that to me after many failed attempts at getting my little noscript to run correctly because I didn't understand why $response variable would be automatically set to something and the noscript wouldn't even wait at the prompt for me to enter something. I had my eyes OPENED today -- and in a frustrating way -- as to how many little tricks and things one must take into account when learning bash noscripting.
So, going back to the noscript, why did I even need to do that or more importantly, WHEN do I need to do that kind of trick again?
p.s. I've been learning from time to time bash noscripting for like the past 3 o 4 months and I know I have to learn a lot more, but Jesus, the journey feels never-ending.
https://redd.it/1j98bb0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to use "cut" correctly
Hi there,
I have a file with urls in it, followed by a little denoscription.
`www.lol.com`
I want to use dmenu to open it in a brower, at the moment, I'm using this line :
But sometimes it fails because xargs takes the full line with the spaces and the denoscription. How would you do to still print the whole line in dmenu, but only takes the first part (url) into args ?
https://redd.it/1j9gewb
@r_bash
Hi there,
I have a file with urls in it, followed by a little denoscription.
`www.lol.com`
///denoscriptionI want to use dmenu to open it in a brower, at the moment, I'm using this line :
cat ~/world/Documents/bookmarks | ~/.config/sway/noscripts/mydmenu -p "Bookmarks:" | xargs -0 -I {} firefox "{}"But sometimes it fails because xargs takes the full line with the spaces and the denoscription. How would you do to still print the whole line in dmenu, but only takes the first part (url) into args ?
https://redd.it/1j9gewb
@r_bash
LOL.com
Welcome Each day contains multiple jokes right now so that we could get our content back up. We’re hoping to eventually have each joke as an individual post, with tags which would be more …
Collections of very useful Bash Functions
I use Bash a lot working with applications, systems, containers or networks, mgmt & integration.
I've found and frequently use a few really useful Bash Github repositories with collections of Bash "Functions" that you can use in your own Bash noscripts.
I've learned a lot from them and have to say my Bash noscripts now have capabilities I'd probably never been smart enough to create myself. In your own noscript(s) you just "source" the file you create or download from the following URLs:
I am sharing this info in case someone else finds them useful.
# Collections of Functions for Bash
GUI'sEasyBashGUI: **https://github.com/BashGui/easybashgui/blob/master/docs/install.md**
>Simplified way to code bash made GUI frontend dialogs!
Script-Dialog: **https://github.com/lunarcloud/noscript-dialog?tab=readme-ov-file**
>Create bash noscripts that utilize the best dialog system that is available. Intended for Linux,
but has been tested on macOS and Windows, and should work on other unix-like OSs.
If it's launched from a GUI (like a
\- it will prefer kdialog in Qt-based desktops and zenity in other environments.
If neither of those are available
\- then
If it's launched in a terminal
\- It will use whiptail or dialog
If neither of those are available, then it will fallback to basic terminal input/output with tools like
Collections of General Bash FunctionsBashMatic: **https://github.com/kigster/bashmatic**
>Bashmatic is a BASH framework, meaning its a collection of BASH functions (almost 900 of them) that, we hope, make BASH programming easier, more enjoyable, and more importantly, fun \- due to the library’s focus on providing the developer with a constant feedback about what is happening, while a noscript that uses Bashmatic’s helpers is running.
Bash-Concurrent: **https://github.com/themattrix/bash-concurrent**
>A Bash function to run tasks in parallel and display pretty output as they complete.
https://redd.it/1j9lkzi
@r_bash
I use Bash a lot working with applications, systems, containers or networks, mgmt & integration.
I've found and frequently use a few really useful Bash Github repositories with collections of Bash "Functions" that you can use in your own Bash noscripts.
I've learned a lot from them and have to say my Bash noscripts now have capabilities I'd probably never been smart enough to create myself. In your own noscript(s) you just "source" the file you create or download from the following URLs:
I am sharing this info in case someone else finds them useful.
# Collections of Functions for Bash
GUI'sEasyBashGUI: **https://github.com/BashGui/easybashgui/blob/master/docs/install.md**
>Simplified way to code bash made GUI frontend dialogs!
Script-Dialog: **https://github.com/lunarcloud/noscript-dialog?tab=readme-ov-file**
>Create bash noscripts that utilize the best dialog system that is available. Intended for Linux,
but has been tested on macOS and Windows, and should work on other unix-like OSs.
If it's launched from a GUI (like a
.desktop shortcut or the dolphin file manager) \- it will prefer kdialog in Qt-based desktops and zenity in other environments.
If neither of those are available
\- then
relaunch-if-not-visible will relaunch the app in a terminal so that a terminal UI can be used. If it's launched in a terminal
\- It will use whiptail or dialog
If neither of those are available, then it will fallback to basic terminal input/output with tools like
read and echoCollections of General Bash FunctionsBashMatic: **https://github.com/kigster/bashmatic**
>Bashmatic is a BASH framework, meaning its a collection of BASH functions (almost 900 of them) that, we hope, make BASH programming easier, more enjoyable, and more importantly, fun \- due to the library’s focus on providing the developer with a constant feedback about what is happening, while a noscript that uses Bashmatic’s helpers is running.
Bash-Concurrent: **https://github.com/themattrix/bash-concurrent**
>A Bash function to run tasks in parallel and display pretty output as they complete.
https://redd.it/1j9lkzi
@r_bash
GitHub
easybashgui/docs/install.md at master · BashGui/easybashgui
EasyBashGUI is a Bash functions library for *BSD and GNU/Linux that aims to give simple GUI functions using yad, gtkdialog, kdialog, zenity, Xdialog, gum, qarma, (c)dialog, whiptail or bash bui...
A noscript to install llama-cpp-python with CUDA enabled
I made an auto-install noscript for myself that I thought some people might find useful or interesting. I have seen posts online where some have claimed to be unable to figure out a way to install llama-cpp-python so for those people maybe this can help and for everyone else this is just a plain fast way to do this.
1. Optionally installs Conda (which I personally recommend doing)
2. Installs the latest version of llama-cpp-python with CUDA enabled from the official llama-cpp-python GitHub repo.
GitHub - llama-installer.sh
FYI, if you choose to install Conda it links to this noscript: GitHub - install_conda.sh
Cheers guys and have a great day.
-J
https://redd.it/1j9nxxn
@r_bash
I made an auto-install noscript for myself that I thought some people might find useful or interesting. I have seen posts online where some have claimed to be unable to figure out a way to install llama-cpp-python so for those people maybe this can help and for everyone else this is just a plain fast way to do this.
1. Optionally installs Conda (which I personally recommend doing)
2. Installs the latest version of llama-cpp-python with CUDA enabled from the official llama-cpp-python GitHub repo.
GitHub - llama-installer.sh
FYI, if you choose to install Conda it links to this noscript: GitHub - install_conda.sh
Cheers guys and have a great day.
-J
https://redd.it/1j9nxxn
@r_bash
GitHub
GitHub - abetlen/llama-cpp-python: Python bindings for llama.cpp
Python bindings for llama.cpp. Contribute to abetlen/llama-cpp-python development by creating an account on GitHub.
how do you combine this 2 parts: touch + strftime ("%F")?
Hi, I'd like to do touch with date today like noum of the file...
how do you do that?
example: touch ..... make this file 2025-03-12
Thank you and regards!
https://redd.it/1j9tnlh
@r_bash
Hi, I'd like to do touch with date today like noum of the file...
how do you do that?
example: touch ..... make this file 2025-03-12
Thank you and regards!
https://redd.it/1j9tnlh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
xarg or sgrep or xmllint or...
All I am trying to do is get
noscript="*"
file="*"
~~~~~
noscript="*"
file="*"
~~~~~
etc
**noscript xml path is:**
/MediaContainer/Video/@noscript
(i think that is how you write noscript being the attribute?).
**file xpath is** :
/MediaContainer/Part/@file
and just write it to a file.
The "file" is always after the noscript so I am not worried about something changing in the structure.
The closest I got (but for only 1 and I have no idea how to get the pair of them) is
find . -iname '*.xml' -print0 | \
xargs -0 -r grep -ro '<Video[ \t].*noscript="[^"]*"' | awk -F: '{print $3}' >>test.txt
Any help would be appreciated.
https://redd.it/1j9zugv
@r_bash
All I am trying to do is get
noscript="*"
file="*"
~~~~~
noscript="*"
file="*"
~~~~~
etc
**noscript xml path is:**
/MediaContainer/Video/@noscript
(i think that is how you write noscript being the attribute?).
**file xpath is** :
/MediaContainer/Part/@file
and just write it to a file.
The "file" is always after the noscript so I am not worried about something changing in the structure.
The closest I got (but for only 1 and I have no idea how to get the pair of them) is
find . -iname '*.xml' -print0 | \
xargs -0 -r grep -ro '<Video[ \t].*noscript="[^"]*"' | awk -F: '{print $3}' >>test.txt
Any help would be appreciated.
https://redd.it/1j9zugv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
is it crazy change rm by mv (file or dir/) ~/.local/share/Trash/files/
Hi, is it possible to do an auto-change from rm to mv file/dir ~/.local/share/Trash/files/ ?
This would avoid being wrong to erase something that I shouldn't erase, so when I do RM Bash changes the RM command for the other command that I put up.
If this is not complicated or just experts. I am not. You already see what I am wrong ...
Thank you and Regards!
https://redd.it/1japd7w
@r_bash
Hi, is it possible to do an auto-change from rm to mv file/dir ~/.local/share/Trash/files/ ?
This would avoid being wrong to erase something that I shouldn't erase, so when I do RM Bash changes the RM command for the other command that I put up.
If this is not complicated or just experts. I am not. You already see what I am wrong ...
Thank you and Regards!
https://redd.it/1japd7w
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A simple Bash function that allows the user to quickly search and match all functions loaded in the current environment
### Idea:
- The following command will display any functions in your environment that contain a direct match to the value of the first argument passed and nothing else.
###
To return any function that contains the exact text
Cheers guys!
https://redd.it/1jb2u8k
@r_bash
### Idea:
- The following command will display any functions in your environment that contain a direct match to the value of the first argument passed and nothing else.
###
To return any function that contains the exact text
Function: $func issue the below command (the listfunc() must be loaded into your environment for this to work), and it will return the entire listfunc() for display (and any other functions that matched as well).list_func 'Function: $func'
list_func() {
# Determine the directory where the bash functions are stored.
if [[ -d ~/.bash_functions.d ]]; then
bash_func_dir=~/.bash_functions.d
elif [[ -f ~/.bash_functions ]]; then
bash_func_dir=$(dirname ~/.bash_functions)
else
echo "Error: No bash functions directory or file found."
return 1
fi
echo "Listing all functions loaded from $bash_func_dir and its sourced noscripts:"
echo
# Enable nullglob so that if no files match, the glob expands to nothing.
shopt -s nullglob
# Iterate over all .sh files in the bash functions directory.
for noscript in "$bash_func_dir"/*.sh; do
# Get file details.
filename=$(basename "$noscript")
filepath=$(realpath "$noscript")
fileowner=$(stat -c '%U:%G' "$noscript") # Get owner:group
# Extract function names from the file.
while IFS= read -r func; do
# Retrieve the function definition from the current shell.
func_body=$(declare -f "$func" 2>/dev/null)
# If a search term was provided, filter functions by matching the function definition.
if [[ -n "$1" ]]; then
echo "$func_body" | grep -q "$1" || continue
fi
# Print the file header.
echo "File: $filename"
echo "Path: $filepath"
echo "Owner: $fileowner"
echo
# Print the full function definition.
echo "$func_body"
echo -e "\n\n"
done < <(grep -oP '^(?:function\s+)?\s*[\w-]+\s*\(\)' "$noscript" | sed -E 's/^(function[[:space:]]+)?\s*([a-zA-Z0-9_-]+)\s*\(\)/\2/')
done
}
Cheers guys!
https://redd.it/1jb2u8k
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Pulling hair out: SSH and sshpass standalone
I have a bit of a problem I have been scrambling to solve and am ready to give up. Ill give it one last shot:
I have a linux system that is connected to a router. THE GOAL is to ssh into the router from the linux system and run a command AND get the output. - seems simple right?
The linux system is pretty outdated. NO INTERNET ACCESS. I have access to commands on this linux system ONLY through PHP functions - don't ask me why, its stupid and I hate it. EG I can run commands by using exec(), I can create new files using file_put_contents(), etc. However because of this I can not interact with the terminal directly. I can create a .bash noscript and run that or run single commands but thats pretty much it.
It is actually over 1000 total systems. All of them running almost the same specs. SOME OF THE TARGET SYSTEMS have GNU
The router uses password authentication for ssh connections. Once logged in you are NOT presented with a full shell, instead you are given a numerical list of specific commands that you can type out and then press enter.
The behavior is as follows:
FROM AN UPDATED LINUX TEST MACHINE CONNECTED TO ROUTER WHERE THE ROUTER IP IS 192.168.1.1:
type "
type "
type the command "
the router returns a code
type the second command "
the router returns a second code
type "
A one liner of this process would look something like:
Except the router does not execute the commands because for some reason it never recieves what ssh sends it. The solution that works on the TEST MACHINE is:
This works every time on the UPDATED TEST SYSTEM without issue even after clearing known hosts file. With this command I am able to run it from php:
and I will get the output which can be parsed and handled.
FROM THE OUTDATED TARGET MACHINE CONNECTED TO THE SAME ROUTER:
target machine information:
The command that works on the updated machine fails. AND RETURNS NOTHING. I will detail the reasons I have found below:
I can use
The version of ssh on the target machine is so old it does not include an option for 'StrictHostKeyChecking=no' it returns something to the effect of "invalid option: StrictHostKeyChecking" sorry I don't have the exact thing. In fact "
After using screen however if I re-execute the first command now it will get farther - because the host is added to known hosts now - but the commands executed on the router will not return anything and neither will ssh itself even with verbose flag. I believe this behavior is caused by an old version of sshpass. I found other people online that had similar issues where the output of the ssh command does not get passed back to the client. I tried several solutions related to redirection but to no avail.
So there is two problems:
1. Old ssh version without a way to bypass host key checking.
2. Old sshpass version not passing the output back to the client.
sshpass not passing back the output of either ssh or the router CLI is the biggest issue - I
I have a bit of a problem I have been scrambling to solve and am ready to give up. Ill give it one last shot:
I have a linux system that is connected to a router. THE GOAL is to ssh into the router from the linux system and run a command AND get the output. - seems simple right?
The linux system is pretty outdated. NO INTERNET ACCESS. I have access to commands on this linux system ONLY through PHP functions - don't ask me why, its stupid and I hate it. EG I can run commands by using exec(), I can create new files using file_put_contents(), etc. However because of this I can not interact with the terminal directly. I can create a .bash noscript and run that or run single commands but thats pretty much it.
It is actually over 1000 total systems. All of them running almost the same specs. SOME OF THE TARGET SYSTEMS have GNU
screen.The router uses password authentication for ssh connections. Once logged in you are NOT presented with a full shell, instead you are given a numerical list of specific commands that you can type out and then press enter.
The behavior is as follows:
FROM AN UPDATED LINUX TEST MACHINE CONNECTED TO ROUTER WHERE THE ROUTER IP IS 192.168.1.1:
ssh `admin@192.168.1.1`type "
yes" and hit enter to allow the unknown keytype "
password" hit entertype the command "
778635" hit enterthe router returns a code
type the second command "
66452098" hit enterthe router returns a second code
type "
exit" hit enterA one liner of this process would look something like:
sshpass -p password ssh -tt -o 'StrictHostKeyChecking=no' `admin@192.168.1.1` "778635; 66452098; exit"Except the router does not execute the commands because for some reason it never recieves what ssh sends it. The solution that works on the TEST MACHINE is:
echo -e '778635\n66452098\nexit' | sshpass -p password ssh -o 'StrictHostKeyChecking=no' -tt `admin@192.168.1.1`This works every time on the UPDATED TEST SYSTEM without issue even after clearing known hosts file. With this command I am able to run it from php:
exec("echo -e '778635\n66452098\nexit' | sshpass -p password ssh -o 'StrictHostKeyChecking=no' -tt admin@192.168.1.1", $a);return $a;and I will get the output which can be parsed and handled.
FROM THE OUTDATED TARGET MACHINE CONNECTED TO THE SAME ROUTER:
target machine information:
bash --version shows 4.1.5uname -r shows 2.6.29ssh -V returns blanksshpass -V shows 1.04 The command that works on the updated machine fails. AND RETURNS NOTHING. I will detail the reasons I have found below:
I can use
screen to open a detached session and then "stuff" it with commands one by one. Effectively bypassing sshpass, this allows me to successfully accept the host key and log in to the router but at that point "stuff" does not pass any input to the router and I cannot execute commands. The version of ssh on the target machine is so old it does not include an option for 'StrictHostKeyChecking=no' it returns something to the effect of "invalid option: StrictHostKeyChecking" sorry I don't have the exact thing. In fact "
ssh -V" returns NOTHING and "man ssh" returns "no manual entry for ssh"!After using screen however if I re-execute the first command now it will get farther - because the host is added to known hosts now - but the commands executed on the router will not return anything and neither will ssh itself even with verbose flag. I believe this behavior is caused by an old version of sshpass. I found other people online that had similar issues where the output of the ssh command does not get passed back to the client. I tried several solutions related to redirection but to no avail.
So there is two problems:
1. Old ssh version without a way to bypass host key checking.
2. Old sshpass version not passing the output back to the client.
sshpass not passing back the output of either ssh or the router CLI is the biggest issue - I
cant even debug what I don't know is happening. Luckily though the router does have a command to reboot (111080) and if I execute:
I wont get anything back in the terminal BUT the router DOES reboot. So I know its working, I just cant get the output back.
So, I still have no way to get the output of the two commands I need executed. As noted above, the "
At this point I am wondering if it is possible to get the needed and updated binaries of both
A friend of mine told me I could use python to handle the ssh session but I could not find enough information on that. The python version on the target machine is 2.6.6
Any Ideas? I would give my left t6ticle to figure this out.
https://redd.it/1jbaskl
@r_bash
echo -e '111080' | sshpass -p password ssh -tt `admin@192.168.1.1`I wont get anything back in the terminal BUT the router DOES reboot. So I know its working, I just cant get the output back.
So, I still have no way to get the output of the two commands I need executed. As noted above, the "
screen" command is NOT available on all of the machines so even if I found a way to get it to pass the command to the router it would only help for a fraction of the machines. At this point I am wondering if it is possible to get the needed and updated binaries of both
ssh and sshpass and zip them up then convert to b64 and use file_put_contents() to make a file on the target machine. Although this is over my head and I would not know how to handle the libraries needed or if they would even run on the target machine's kernel. A friend of mine told me I could use python to handle the ssh session but I could not find enough information on that. The python version on the target machine is 2.6.6
Any Ideas? I would give my left t6ticle to figure this out.
https://redd.it/1jbaskl
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community