how to write the script to know each sample's cluster number?
Assuming you are following the basic seurat guide:

pbmc@ident


You can access the 'ident' slot of your Seurat object and you will get a vector of the cluster IDs and the names will be the respective cells.

head(seuratobj@ident)
Cell1A7 Cell1C4 Cell1D1 Cell1D2 Cell1D3 Cell1D5
0 3 3 1 3 1 
Levels: 0 1 2 3 4