How do I name the output textfile to YYYYMMDD based on the system date? - sqlcmd

How do I name the output textfile to YYYYMMDD based on the system date?
sqlcmd -S DataBBB -i c:\scripts\followup.sql
-o %DATE:~4,2%_%DATE:~7,2%_%DATE:~-4%.txt -s ; -W -u
Now the output text file is 01_31_2012.txt.
How can I change it to 2012_01_31.txt?

Tried it under Windows 7 Premium (German), may be dependent upon OS and Local Time Format.
sqlcmd -S DataBBB -i c:\scripts\followup.sql
-o %date:~-4%_%date:~3,2%_%date:~0,2%.txt -s;
You have to edit this part for your system
%date:~-4%_%date:~3,2%_%date:~0,2%.txt
The statement used the command line internal %date% - variable with the extension :~start,length. So you can create the filename with different parts from the date- variable.

Related

bash script continues to show "does not exist. file "

I'm running this bash scripts to read a CSV File which contains almost 10 lines with 05 columns:
Variables Global
DATE=$(date) #Set DATE equal to the output of running the shell command date
HOSTNAME=$(hostname) #Set HOSTNAME equal to the output of the hostname command
CSV_FILE='/scrpt/jobs_aix01.csv'
CSV_DELIMITADOR=','
#Variables
contador_sql=0
cadena_sql="error"
## Script
while IFS=\, read col_job_name col_os col_server col_user col_script
do
#echo "$col_job_name $col_os $col_server $col_user $col_script"
ls -l $col_script
done < "$CSV_FILE"
The script must read the CSV file and run the command ls -l but I get "does not exist. file "
Any ideas?
note: the files exist.
regards
unix jose

the system cannot find the file specified while importing json data in couchbase bucket.

I apologize if my question does not deserve a standard to ask here.
I have two files(products-data.json, orders-data.json) inside the following directory:
G:\kb\Couchbase\CB121
and I imported the products-data.json successfully using the following command:
G:\kb\Couchbase\CB121>cbimport.exe json -c couchbase://127.0.0.1 -u sattar -p 156271 -b sampleDB -f lines -d file://products-data.json -t 4 -g %type%::%variety%::#MONO_INCR#
But when I try to import orders-data.json in the same way as follows:
G:\kb\Couchbase\CB121>cbimport.exe json -c couchbase://127.0.0.1 -u sattar -p 156271 -b sampleDB -f lines -d file://orders-data.json​ -t 4 -g ​%type%::%order_id%
I am getting the following error:
2018-01-21T12:01:31.211+06:00 [31mERRO: open orders-data.json​: The system cannot find the file specified.[0m[2m -- jsondata.(*Parallelizer).Execute() at source.go:198[0m
2018-01-21T12:01:31.212+06:00 [31mERRO: open orders-data.json​: The system cannot find the file specified.[0m[2m -- plan.(*data).execute() at data.go:89[0m
Json import failed: open orders-data.json​: The system cannot find the file specified.
It kills my day. Any help is appreciated. Thanks.

Adding a column (first column) to csv file with service names and the status

I am using below code to redirect service names and status on my centos box to a csv file:-
service --status-all |
grep -E running\|stopped |
awk '{print $1,","," ",$NF,","," "}' >> "$HOME/MyLog/running_services_$HOSTNAME.csv"
Output for service --status-all command on my box is like:-
httpd is running
Now, I basically need the first column in this csv file as the ip address of the centos box. I can get the IP using this:-
ifconfig | sed -En 's/127.0.0.1//;s/.inet (addr:)?(([0-9].){3}[0-9])./\2/p'
Output of above command is:- 192.168.0.38 (IP address of my host).
Current CSV Output is like:- ServiceName Status
I would need the output to be as:- IP Address ServiceName Status
I need to know how can I insert the first column in this CSV which will have the IP address for each of the rows - populated with service names and status. Any pointers on this?
Can I print this command output as first column using awk?
Thanks.
Capture the IP address first, and give the value to awk
ip=$( ifconfig | sed -En 's/127.0.0.1//;s/.inet (addr:)?(([0-9].){3}[0-9])./\2/p' )
service --status-all | awk -v ip="$ip" -v OFS="," '/running|stopped/ {print ip, $1, $NF}' >> "$HOME/MyLog/running_services_$HOSTNAME.csv"
Note that you don't need grep: awk can do that job.

Creating custom DVD for RHEL 7 with kickstart

I am trying to create a custom CD/DVD to deploy RHEL 7 with kickstart file. Here is what I did:
Edited isolinux.cfg (in the ISOLinux folder) and grub.cfg file (in the EFI\BOOT folder).
Created ISO using mkisofs.
But it is not working. Am I using correct files/method?
Edit the ISO image and put the ks.cfg file that you have created.
Preferably, put the ks.cfg file inside ks directory. More information can be found here.
You need to use the new command. Here is an example of what will work:
Add the kickstart file to your download and exploded ISO.
Run this command in the area with the ISO and kickstart and point to another location to build the ISO:
genisoimage -r -v -V "OEL6 with KS for OVM Manager" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o OEL6U6_OVM_Manager.iso /var/www/html/Template/ISO/
I found the way to create custom DVD from the RHEL7 page.
Mount the downloaded image
mount -t iso9660 -o loop path/to/image.iso /mnt/iso
Create a working directory - a directory where you want to place the contents of the ISO image.
mkdir /tmp/ISO
Copy all contents of the mounted image to your new working directory. Make sure to use the -p option to preserve file and directory permissions and ownership.
cp -pRf /mnt/iso /tmp/ISO
Unmount the image.
umount /mnt/iso
Make sure your current working directory is the top-level directory of the extracted ISO image - e.g. /tmp/ISO/iso. Create the new ISO image using genisoimage:
genisoimage -U -r -v -T -J -joliet-long -V "RHEL-7.1 Server.x86_64" -Volset "RHEL-7.1 Server.x86_64" -A "RHEL-7.1 Server.x86_64" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -o ../NEWISO.iso .
Hope the answer will helpful:
I am editing my answer due to the comments posted. Here is a more comprehensive solution:
(A) You need to create the ISO properly. I found helpful information in this URL.
Here is the line that I actually ended up with, for my MBR/UEFI ISO creation:
mkisofs -U -A "<Volume Header>" -V "RHEL-7.1 x86_64" -volset "RHEL-7.1 x86_64" -J -joliet-long -r -v -T -x ./lost+found -o ${OUTPUT}/${HOST}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -boot-load-size 18755 /dir/where/sources/for/ISO/are/located
Be careful with the -V parameter, as it has to match what the kernel has defined for inst.stage2. In the default grub.conf included in the boot disk, it is configured to be "hd:LABEL=RHEL-7.1\x20x86_64" which matches with the settings above.
(B) You need the correct setup for EFI for RHEL7. For some reason, this has changed from RHEL6, where you could just use the /EFI/BOOT/BOOTX64.conf. Now it uses the /EFI/BOOT/grub.cfg. Common wisdom from Red Hat Manuals state to add the inst.ks= parameter to the kernel line. The grub.cfg that comes in the /EFI/BOOT directory of the RHEL7 boot iso actually has the linuxefi parameter, instead of the kernel one, I would guess they would work the same. If you are including the KS file on the CD, this should get you there.
Good Luck!

Bash for loop picking up filenames and a column from read -r and gnu plot

The top part of the following script works great, the .dat files are created via the MySQL command, and work perfectly with gnu plot (via the command line). The problem is getting the bottom (gnuplot) to work correctly. I'm pretty sure I have a couple of problems in the code: variables and the array. I need to call each .dat file (plot), have the title in the graph (from title in customers.txt)and name it (.png)
any guidance would be appreciated. Thanks a lot -- RichR
#!/bin/bash
set -x
databases=""
titles=""
while read -r ipAddr dbName title; do
dbName=$(echo "$dbName" | sed -e 's/pacsdb//')
rm -f "$dbName.dat"
touch "$dbName.dat"
databases=("$dbName.dat")
titles="$titles $title"
while read -r period; do
mysql -uroot -pxxxx -h "$ipAddr" "pacsdb$dbName" -se \
"SELECT COUNT(*) FROM tables WHERE some.info BETWEEN $period;" >> "$dbName.dat"
done < periods.txt
done < customers.txt
for database in "${databases[#]}"; do
gnuplot << EOF
set a bunch of options
set output "/var/www/$dbName.png"
plot "$dbName.dat" using 2:xtic(1) title "$titles"
EOF
done
exit 0
customers.txt example line-
192.168.179.222 pacsdbgibsonia "Gibsonia Animal Hospital"
Error output.....
+ for database in '"${databases[#]}"'
+ gnuplot
line 0: warning: Skipping unreadable file ".dat"
line 0: No data in plot
+ exit 0
to initialise databases array:
databases=()
to append $dbName.dat to databases array:
databases+=("$dbName.dat")
to retrieve dbName, remove suffix pattern .dat
dbName=${database%.dat}