Bash script produces bullets in filename - linux

I new to bash scripts. By doing "Google search programming," I've managed to write this one:
#------------------------
_dir="/volume1/Shared/sqlbackup/"
_date=`date +"%Y_%m_%d_%H_%M_%S"`
_file="$_dir$_date.gz"
/usr/syno/mysql/bin/mysqldump -u username -ppassword database | gzip > "$_file"
#------------------------
At the end of running it using a Windows 7 telnet interface, I get a filename that looks something like this, when viewing it on a Windows 7 share:
2013_10_09_13_38_36.gz
The "?" boxes here show up as bullets (like •) on Windows. Obviously, I'm doing something wrong. Does anyone have suggestions.
Thanks.

You can use the dos2unix and unix2dos utilities to convert text files between Linux and Windows formatting. e.g.
dos2unix script.sh

Related

searching text in a file remotely

I have log files, based on Linux servers, and I'm working on Windows OS.
I'm using Filezilla to log in the Linux server and searching specific text or strings by open the log file.
I want to automate this process using batch in Windows, I tried using below;
#echo off
cls
set /p string="Enter the string: "
echo open xx.xx.xx.xx 21> ftpc.dat
echo xxxxxxxx>> ftpc.dat
echo xxxxxxxx>> ftpc.dat
echo bin >> ftpc.dat
echo grep '%string%' /PATH IS HERE/log.log >> ftpc.dat
ftp -s:ftpc.dat
I'm just new to that, I want ideas on that, how I automate this search process? where I can make a search tool for any text, that this tool goes and find specific file in linux server and shows the results in lines (before/after 15 lines) of thatsearch results.
Do I need to write bash scripts, or I can do this basic script in batch file as above to show or output the results?
If you have a number of Linux servers to watch, it might be worth installing something like rsyslog or logstash. It's a big topic, but those might be good starting points in your research.
Other things to google: elasticsearch, kibana ... and their alternatives.
You cannot run grep using FTP.
So either:
Use FTP to download whole file and grep/search it locally.
Or (as you seem to have an SSH access too) use a command-line SSH client to execute grep on the server. On Windows, you can use Plink (which comes with PuTTY):
plink -pw password user#example.com grep '%string%' /remote/path/log.log >

SHELL to TXT, Is It Possible?

I created a .sh file in Linux Server and would like to convert it into a text file for windows or Linux mint. Is that possible of doing?
Thank You!!!
In windows right click on it and click "Open with..." and choose notepad.
In mint go to terminal and use either vi or nano to edit the file:
vi /path/to/file/file.sh
Well, not sure if it is what you wanted, but if you have i.e. file named script.sh, you can simply redirect it to another file by executing
cat script.sh > script.txt
However, be aware that EOF in linux is different than in Windows, so you can use this.
just copy the contents from sh file into another file within linux or run this command
cp file.sh file.txt

Any command we can use to convert windows file to unix or mac file?

I don't want to use dos2unix tool. I want to use command in Ubuntu terminal to convert Windows file to Unix file. Is that possible. I have looked through other articles and tried those commands but none working. Anyone can help?
You can use tr to remove carriage returns like this:
tr -d '\r' < WindowsFile > UnixFile
You can use
cat -vet WindowsFile
to see if there are carriage returns in your file and they'll show up as ^M
I want to use command in Ubuntu terminal to convert Windows file to Unix file.
dos2unix path/to/file/to/convert
I don't want to use dos2unix tool.
alias notdos2unix=dos2unix
notdos2unix path/to/file/to/convert
For Ubuntu(and Debian) you can use the tofrodos package.
sudo aptitude install tofrodos
fromdos file.txt # converts the file to UNIX line-endings
todos file.txt # converts the file to Windows line-endings
OSX (being a derivative of UNIX) should have the same line-endings as UNIX.
If you're on Windows, you can find tofrodos binaries here.
If you're on a Mac, you can use the brew package manager and install the tofrodos on OSX.

Linux command to DOS

I have a file include some linux command and I want to run in on windows (DOS command).
The command is:
cat tmp/$id/index.html | sed -e 's/ID/$id/g' > a;mv a tmp/$id/index.html
What is the similar command in MS-DOS?
Thank you!
The problem is that natively there is no equivalent command to sed. You have two options from my point of view. Either create a vb script that does what you want (It will not take 1 line though - more like 10-15 I guess), or use something like GnuWin32 that gives you the option to run unix commands in windows terminal.
You could consider using powershell to do approximately the same thing. It supports cat and mv and you can get a sed like equivalent by using %{_ -replace "expression", "replace"}. Details here http://blogs.msdn.com/b/zainnab/archive/2007/07/09/grep-and-sed-with-powershell.aspx
Or consider using a linux like command prompt like bash which should be available through cygwin
I think this is impossible to do in "bare" command line (as you called DOS command), because cat and sed are separate utilities. If you want to port this script from Linux command shell to windows command line, I would advise you to download and install CygWin
DOS itself does not have support for that. You could try with a port of SED for DOS available here. If you can get Powershell, that's an option. Here's an example of using grep/sed with Powershell.
There are many options.
You can try to install cygwin or download and install Git and use Git-bash or add the bin directory to your PATH so you can run this command on your CMD prompt.
There is no such command(s) for MS-DOS.

convert cygwin bash into tcsh

how can I be able to convert my cygwin bash into a c Shell.
I have tried by changing the .bat file in installation directory like:
#echo off
#echo ----Welcome NAME----
#echo 'have a nice day'
cygdrive\
chdir \
set HOME=\cygwin\home\
tcsh -i
please help.
Is it right process?
though it is working for me a bit...
any ideas...?
To change your Cygwin shell, you can alter the /etc/passwd file. Each line is a delimited list of user accounts, where the last entry is the shell for that user. Simply change the line that reads, for example:
abhisek:[some other stuff]:/usr/bin/bash
to:
abhisek:[some other stuff]:/usr/bin/tcsh
The current version of Cygwin doesn't have an /etc/passwd file, and the system I'm working on has Windows account information in a domain database out of my control. Consequently, chsh is no longer supported.
I also found that bash is not hard-coded into the startxwin script, nor is it hard-coded in any .bat file. Turns out you don't need to fiddle with .bat files at all.
Searching for how to change my shell, I found some advice about mkpasswd
I added it to the mix.
The man-page said:
SYNOPSIS
mkpasswd [OPTIONS]...
OPTIONS
Don't use this command to generate a local /etc/passwd file, unless you
really need one. See the Cygwin User's Guide for more information.
-c,--current
Print current user.
DESCRIPTION
The mkpasswd program can be used to create a /etc/passwd
file. Cygwin doesn't need this file, because it reads user
information from the Windows account databases, but you can add
an /etc/passwd file, for instance if your machine is often dis‐
connected from its domain controller.
Note that this information is static, in contrast to the informa‐
tion automatically gathered by Cygwin from the Windows account
databases. If you change the user information on your system,
you'll need to regenerate the passwd file for it to have the new
information.
For very simple needs, an entry for the current user can be cre‐
ated by using the option -c.
(I don't know why the spacing is so "off"...)
I then used the following command:
mkpasswd -c | sed -e 'sX/bashX/tcshX' | tee -a /etc/passwd
and voila! the next time I opened a Cygwin Terminal, it went straight to tcsh
And that's the way (Uh-huh, uh-huh!) I like it.

Resources