Setting Shell Script Variable

Associate
Joined
12 Oct 2005
Posts
1,511
Location
Surrey
Trying to write a script which includes a defined date variable to be used in naming and referencing files.

Snippet from sar_tool.sh:

#!/bin/bash

day='date +%d'
date='date +%d&m&y'

#Export
export LC_ALL=C

#Convert today's sa file into a text file with today's date
sar -A -f /var/log/sa/sa$day > /var/log/sa/ksar/sa$date.txt

Essentially there will already be a file in /var/log/sa called for example:

sa24

Which I need to convert into a text file with the naming convention for example:

sa240309


When I run the script bash complains about my sar syntax and a file called sadate +%d%m%y.txt can be found in /var/log/sa/ksar.

The command:

sar -A -f /var/log/sa/sa24 > /var/log/sa/ksar/sa24.txt

works fine.
 
Back
Top Bottom