Noob here.
I have ccminer-cryptonight compiled and running on my ubuntu 16.04 thinkpad.
However, since my nvidia gpu is old and not supported by the latest cuda, I have to use the integrated Intel gpu for X and use bumblebee for ccminer and nvidia gpu so my screen wouldn't freeze...
here is the command I use:
optirun ccminer -a cryptonight -o stratum+tcp://miningpooladdress.com:5000 -u username -p "password" -P -R 15
ccminer gives a lot of output I only want to monitor the hashrate since there is a bug when the hashrate goes insanely high which means ccminer has stopped mining, so I have to kill it and restart.
this is the awk command I use to parse hashrate:
optirun ccminer -a cryptonight -o stratum+tcp://miningpooladdress.com:5000 -u username -p "password" -P -R 15 2>&1 | awk '/5400M,/ {print $7}'
which parse the line of hashrate readout, my card is NVS 5400M, the output looks like:
43.43
54.23
32.67
44.89
xx.xx
xx.xx
Now I want to write this output to a log file, I tried:
optirun ccminer -a cryptonight -o stratum+tcp://miningpooladdress.com:5000 -u username -p "password" -P -R 15 2>&1 | awk '/5400M,/ {print $7 >> "logfile"}'
and
optirun ccminer -a cryptonight -o stratum+tcp://miningpooladdress.com:5000 -u username -p "password" -P -R 15 2>&1 | awk '/5400M,/ {print $7}' >> "logfile"
none of these two works, the "logfile" will be created but remain empty what am I doing wrong? Why can I get the screen output but can't write to the file?
Thanks for helps.
Update regarding ccminer-cryptonight: a simple solution of lazy miner behaviours - run as root ;P
awk is buffering its output so change your awk command to:
awk '/5400M,/ {print $7; fflush()}'
For other buffering issues, google stdbuf.
Related
I am trying to create shell script that ssh into a remote server and run a script there and print the output in the local server but when I run the script in the local server it most of the time outputs nothing and rarely outputs data :
Mule: CPU > % RAM > %
and when I ssh in the local server to the remote server in the command line and run the script it outputs normally in the command line :
Mule: CPU > 39.0% RAM > 8.1%
the script in local server
#!/bin/bash
echo -e '\r'
echo 'leg3'
echo -e '\r'
ssh -qT appread#${remote} << EOF
source /home/appread/Process_mon.sh
exit
EOF
script in remote server :
#!/bin/bash
mulecpu=$(top -b -n 1 -c | grep -P '.*[j]ava.*mule.*'| awk '{print $9}')
muleram=$(top -b -n 1 -c | grep -P '.*[j]ava.*mule.*'| awk '{print $10}')
m=$(echo 'Mule: CPU > '$mulecpu'% RAM > '$muleram'% ')
echo $m
If you run top without -w, its output may be truncated and so your grep may fail.
Add -w 512 or similar to maximise the width of the output:
#!/bin/bash
top -b -n 1 -c -w 512 |\
awk '/[j]ava.*mule/ { printf "Mule: CPU > %s%% RAM > %s%%\n",$9,$10 }'
I has running a daemon program to monitor a specific directory file changes, at the beginning, program is running normally, but after a period of time, inotifywait does work at the time of file changes. When i restart the program, it gets back to normal again. This is my shell script:
#!/bin/sh
./etc/puppet/modules/config.sh
puppetmaster=`grep -w server ${puppet_config} | awk -F'=' '{print $2}'`
/usr/local/bin/inotifywait -mrq -e modify ${log_dir}| while read D E F
do
/usr/bin/rsync -i -p -H -S -z -r -A -o -g -a --port=${port} \
--timeout=600 --exclude='.svn/' --exclude='.git/' ${log_dir}/ \
rsync://${puppetmaster}/log_dir > /dev/null
done
Please someone help me.Thanks..
Please share more ideas to get software version from bash command and use it as variable later.
su --version
su (GNU coreutils) 5.97
Copyright etc.
and create variable of the result of it.
Something like I tried below.
su --version >/tmp/temp.txt
if [ -f /tmp/temp.txt ]; then
elv=`cat /tmp/temp.txt | gawk 'BEGIN {FS="(GNU coreutils)"} {print $2}' | gawk 'BEGIN {FS="."} {print $1}'`
#Version String. Just a shortcut to be used later
els=el$elv
else
echo "Unable to determine version. I can't continue"
exit 1
fi
if [ `rpm -qa | egrep -c -i "^mysql-"` -gt 0 ]; then
cat << EOF
It appears that the distro-supplied version of MySQL is at least partially installed,
or a prior installation attempt failed.
Please remove these packages, as well as their dependencies (often postfix), and then
retry this script:
$(rpm -qa | egrep -i "^mysql-")
EOF
exit 1
fi
I believe this is a simple syntax issue on my part but I have been unable to find another example similar to what i'm trying to do. I have a variable taking in a specific disk location and I need to use that location in an hdparm /grep command to pull out the max LBA
targetDrive=$1 #/dev/sdb
maxLBA=$(hdparm -I /dev/sdb |grep LBA48 |grep -P -o '(?<=:\s)[^\s]*') #this works perfect
maxLBA=$(hdparm -I $1 |grep LBA48 |grep -P -o '(?<=:\s)[^\s]*') #this fails
I have also tried
maxLBA=$(hdparm -I 1 |grep LBA48 |grep -P -o '(?<=:\s)[^\s]*')
maxLBA=$(hdparm -I "$1" |grep LBA48 |grep -P -o '(?<=:\s)[^\s]*')
Thanks for the help
So I think here is the solution to your problem. I did basically the same as you but changed the way I pipe the results into one another.
grep with regular expression to find the line containing LBA48
cut to retrieve the second field when the resulting string is divided by the column ":"
then trim all the leasding spaces from the result
Here is my resulting bash script.
#!/bin/bash
target_drive=$1
max_lba=$(sudo hdparm -I "$target_drive" | grep -P -o ".+LBA48.+:.+(\d+)" | cut -d: -f2 | tr -d ' ')
echo "Drive: $target_drive MAX LBA48: $max_lba"
I am relatively new to using scp - and I am trying to do some simple stuff over ec2 - something like the following:
scp -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file
What I would like to have is the log of the above command (i.e the screen output to a text file) - Is there a way to achieve this?
Thanks.
You can redirect both outputs (stdout, stderr) of the command with &> provided you use the verbose (-v) argument. Otherwise, scp will suppress the output as it expects its stdout to be connected to a terminal. But then you get too much information, which you can get rid of with grep:
scp -v -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^debug > file.log
If you want to have the output both to the screen and the file, use tee
scp -v -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^ debug tee file.log
scp -v -i ec2key.pem username#ec2ip:/p/t/file ~/p/t/d/f/file >> something.log 2>&1
-v and 2>&1 will append your extended details (i.e. debug info) in the existing something.log file.
How about (untested, compressing /path/to for readability):
(scp -i ec2key.pem username#ec2ip:/p/t/file ~/p/t/d/f/file ) 2>/p/t/textfile