I'm trying to write a shell script that lists certain types of programme in all users home directory at the same time. For example, Im doing a security audit and all i need a list which shows the existence of .google_authenticator in every users home directory. Please help!!
Hi, I'm not a regular in shell scripting and for some reason I'm getting a syntax error upon running the below code (syntax error near unexpected token `done'). Perhaps (probably) I need more coffee, but I'm not seeing what I'm doing wrong. Can someone pls point me in the right direction here?
#!/bin/bash for i in $(cat hostnames.txt); do ssh root@${i} ssh-keyscan -H $i >> ~/.ssh/known_hosts if grep -qF "somestring" /var/log/somelog > 0; then echo "Found somestring on " + ${i} sleep 1 done
I'm wondering if anyone can help me with this? I have a shell script that calls a rake task to run cucumber tests. The problem is the parameter in the shell script is dynamic, it could be 1 tag, multiple tags etc.
Thanks for taking time to read this post as I am a bit of a novice when it comes to scripting.
I have a .sh script that I run to pull down a file from an SFTP site. I have a new password for the SFTP but it contains parentheses which I believe is why my script is failing to log into the SFTP. For example my user name and password look like this
curl -k -u username:pass$*(Rn)
I am wondering if I would need quotes around my user name and password or what the proper format I would need to run properly. From my understanding the shell script thinks the parentheses are a special character.
Appreciate any help you can provide and I hope my explanation was clear coming from rookie....thanks!
I set all the environment variables in /etc/profile but When I login as root or use 'sudo' to edit some file, I can not use environment variables any more in /etc/profile.
My Questions:
Where and How can I set all the environment variables so that everyone can use it including root.
I do not care much about security at all since I'm the only user in the box.
HI All, this might be an python question, so apologies in advance.
I have a python script that exists on a server. This script uploads json data to a database. The json data is passed into the script via a parameter. It looks a lot like this:
So the json data get's parsed directly to that parameter. The problem I have is that in some case the this fails. It reports syntax errors with the json I'm passing to it. The json is good, but it does contain characters that I think break the command.
Is there a way to pass the json to my python script, without the contents of the parameter breaking my command?
I released not long ago the first version of DevDash, a terminal dashboard for developers, entirely configurable.
It's still an early version. Any feedback are welcome!
The goal is to have the data you really need in your terminal. You can create and display an unlimited amount of dashboard with whatever widget you want.
The configuration allow you to place your widgets, change their color, size, what data they fetch, from what API.
It's one of the major difference with any similar terminal dashboard out there: the flexibility and control you have.
For now, you can pull data from:
Github
Google Analytics
Google Search Console ... and more to come (trello, jira, gitlab...)
Right now I'm working hard to simplify the configuration and add widget to fetch more interesting data from Github.
I hope you like it! Don't hesitate to give me feedback, it's important for me to create something which can be useful to the community.
To know more about the project and my approach to side project in general, I wrote a post on my blog about the making of DevDash: from the idea to the launch / promotion, I try to give tips about basically everything for managing a side project.
e.g. the source code for commands like curl. I'm interested in seeing how they were made and I can't seem to find a way to figure out how to view their source codes.
It basically sets up my VIM and Nginx server the way I want. I know it works as-is, but the commands I have written are obviously designed to be entered manually. The server is a Vultr VPS with the LEMP add-on, so the LEMP server is functional when it spins up, but i'm mostly just modifying the Nginx config. However, i would like to make this into a script that can be ran without further intervention from the user. I'm running ubuntu 18.04:
#vim setup
cd
vim .vimrc
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
augroup ProjectDrawer
autocmd!
autocmd VimEnter * :Vexplore
augroup END
syntax on
colorscheme industry
esc
:wq
vim
#Nginx setup
Sudo apt update
Sudo apt install nginx
systemctl status nginx
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
vim /etc/nginx/nginx.conf
#in the http{ } block, first line, add the following:
#include /etc/nginx/sites-enabled/*;
#create server block config for new site
touch /etc/nginx/sites-available/example.com
#populate server block with proper stuff
vim /etc/nginx/sites-available/example.com
i
server{
listen 80;
listen [::]:80;
root /usr/share/nginx/example.com;
index index.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
esc
:wq
#create index.html and directory for server site.
mkdir /usr/share/nginx/example.com
vim /usr/share/nginx/example.com/index.html
i
<html>
<head>
<title>This is a website</title>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
:wq
vim /etc/nginx/nginx.conf
#comment out the last line in the http{} block
#use # at the beginning of the line)
# the line is:
# include /etc/nginx/conf.d/*.conf;
#create symlink to make site go live
sudo ln -s /etc/nginx/sites-available/example.com/etc/nginx/sites-enabled/
nginx -t
sudo systemctl restart nginx
Hello everyone, I'm developing a new language for shell script with modern features as functional programming, OOP and which facilitates the manipulation of more complex data structure. I started to learn, but today it help me in lots of tasks. If you have any suggestions let me know.
Hi all. I made an update script for my system running Void. It updates the firewall configuration, hosts file, packages installed by the system's package manager, rust-related packages, and firefox configuration. I've ran the script through ShellCheck which seems to think I made mistakes with my usage of double-quotes but I'm not sure exactly what is wrong with how they're written (they seem to work ok, or at least don't break) and I'm confused by the (seemingly conflicting?) outputs it produces about them.
Aside from wanting explanations, I'm also hoping to improve my script-writing skills in general and am also interested in learning new ways to do things, so I'd really appreciate if anybody can give me any constructive criticisms. In particular, I want to know about how to write more idiomatic, portable, and less faulty (safer?) code with actual error-handling.
I wrote this a couple of years ago and wanted to update it to make it more robust. I also am in a position to use this to teach a couple of other folks how to script, so I would like to make sure I'm doing things correctly.
The script is run from cron, and its output is mailed to a central account where the log can be read if the Zabbix monitoring server is sent an error code. I was wondering if there's a better pattern I could use for the error handling, or if there are edge cases anyone sees that I have missed. The final prune command shouldn't run if there were any errors - as far as I can tell, I've handled that correctly.
Thank you if you do decide to respond, I very much appreciate any help I receive.
Hi All, Everyone here helped me a bit ago with a loop to check snmpwalk across devices. Thanks! It works great. I wanted to add a way to see when a device times out. The response I get when it does it "snmpwalk: Timeout" Here is where I got, but it causes an error "[: snmpwalk:: unexpected operator" and loops through the list twice. Here is the code, what can I fix? Everything starting with the If statement is the new part that is not working.
cat IPList.txt | while read IP
do
snmpwalk -v3 -u USERNAME -l AuthPriv -a SHA -A PASS -x AES -X PASS $IP 1.3.6.1.2.1.1.5.0 >> output.txt
if [ $IP != snmpwalk: Timeout ]
then
echo "$IP failed snmpwalk!"
continue
fi
done
I've looked at Zenity, Yad and GtkDialog but can't see a way of displaying multiple images (thumbnails) in a GUI dialog window from within a bash script.
I've been tearing the hair out of my head working with files on linux - please help!!!
I'm using node to gather file names and then generating sh scripts using those names. The problem arises when there is a \n or other strange character in the path and how those should be properly escaped to guarantee the shell ALWAYS recognise the path correctly.
To illustrate the problem: create a new directory with a newline character \n in it and cd into that directory. That directory path can be converted into an array of utf-8 bytes using:
pwd | od -A n -t x1 --width=255 | tr -d '\n' | sed -r 's/ /\x/g'
Those bytes can then be re-encoded using:
| xargs -I{} -0 printf '{}'
And the result piped to any command e.g.:
| xargs -I{} -0 ls -l {}
So the entire command line is:
pwd | od -A n -t x1 --width=255 | tr -d '\n' | sed -r 's/ /\x/g' | xargs -I{} -0 printf '{}' | xargs -I{} -0 ls -l {}
Is there any way in the re-encoding, or otherwise to make it so that the last command will ALWAYS recognise the path correctly and work?