If you need to set a password from a command line automatically, you can use the following script:
echo myPassword | passwd myUser --stdin
This will ensure your password is send via pipe into passwd and set appropriately. It can be useful when you need to assign same password on different servers, so you can run this command remotely, over ssh.
A blog about tips and tricks for linux - as I do some development, sometimes I find some good staff which I would like to store somewhere. I will be happy if you find this stuff to be useful for any reason.
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
Wednesday, April 22, 2015
Sunday, April 12, 2015
How to create large PDF file in MACos for testing
Recently I needed to create a set of large PDF files to be used for testing. The files had to be very large, and have to be processed by a search engine for indexing. It was important to have a custom content in them, as well as make sure they do not have many images, but a lot of text. That had to be processed later and be available for searching. With the code snippet below you can create a set of such PDF files, and use them for whatever purpose you need to.
Here is how I did it. Step 1. I wrote a simple script, which prepares a text file to be converted to PDF:
#!/bin/bash
echo "" > testContent.txt
for i in {1..5000}
do
echo "Test content to fill into large pdf." >> testContent.txt
done;
cupsfilter testContent.txt > large0.pdf 2>/dev/null
Note that you should be able to adjust amount of text you would like to see in the file, and the text itself, so the content looks exactly how you want to see it. The final large0.pdf if the test PDF file, which you need. cupsfilter command (http://linux.die.net/man/8/cupsfilter) actually converts text file into another format, by default into PDF.
You can read more about cupsfilter by reading cupsfilter connmmand syntax description on developer.apple.com
I will show in next article, how from a single PDF file you can create a set of files of multiple sizes.
Here is how I did it. Step 1. I wrote a simple script, which prepares a text file to be converted to PDF:
#!/bin/bash
echo "" > testContent.txt
for i in {1..5000}
do
echo "Test content to fill into large pdf." >> testContent.txt
done;
cupsfilter testContent.txt > large0.pdf 2>/dev/null
Note that you should be able to adjust amount of text you would like to see in the file, and the text itself, so the content looks exactly how you want to see it. The final large0.pdf if the test PDF file, which you need. cupsfilter command (http://linux.die.net/man/8/cupsfilter) actually converts text file into another format, by default into PDF.
You can read more about cupsfilter by reading cupsfilter connmmand syntax description on developer.apple.com
I will show in next article, how from a single PDF file you can create a set of files of multiple sizes.
Friday, November 7, 2014
Random password in bash
Sometimes you may need to generate some random password. Bash can help you with that task. For any of the commands below you can modify them to adjust to your needs, i.e. modify the length or the logic.
16-character-long password based on date and base64/SHA encoding:
Another example using built-in /dev/urandom command:
Now the simplest command, which will work in any environment.
16-character-long password based on date and base64/SHA encoding:
date +%s | base64 | sha256sum | head -c 16 ; echo
Another example using built-in /dev/urandom command:
< /dev/urandom tr -dc a-zA-Z-0-9 | head -c 16 ; echo;
Now the simplest command, which will work in any environment.
date | md5sum
date | md5sum | head -c 8
Tuesday, May 7, 2013
logging in bash - nice subroutine to reuse
I had a need to support good logging capabilities in bash. The reason was that there were quite a few scripts which needed consistent logs being rolled over every day. Here is the solution which I have come up with. As a result, a separate log file is created with datestamp in the filename.
Monday, September 24, 2012
How to remove all repositories using zypper
If you need to remove all repositories, use this command:
zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}' | bash
I would suggest first to try to see the output of the command without the last bash:
zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}'
zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}' | bash
I would suggest first to try to see the output of the command without the last bash:
zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}'
Subscribe to:
Posts (Atom)